Annotation of embedaddon/strongswan/src/libstrongswan/plugins/ntru/ntru_convert.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2014 Andreas Steffen
                      3:  * HSR Hochschule fuer Technik Rapperswil
                      4:  *
                      5:  * Copyright (C) 2009-2013  Security Innovation
                      6:  *
                      7:  * This program is free software; you can redistribute it and/or modify it
                      8:  * under the terms of the GNU General Public License as published by the
                      9:  * Free Software Foundation; either version 2 of the License, or (at your
                     10:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                     11:  *
                     12:  * This program is distributed in the hope that it will be useful, but
                     13:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     14:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     15:  * for more details.
                     16:  */
                     17: 
                     18: /**
                     19:  * @defgroup ntru_convert ntru_convert
                     20:  * @{ @ingroup ntru_p
                     21:  */
                     22: 
                     23: #ifndef NTRU_CONVERT_H_
                     24: #define NTRU_CONVERT_H_
                     25: 
                     26: #include <library.h>
                     27: 
                     28: /**
                     29:  * Each 3 bits in an array of octets is converted to 2 trits in an array
                     30:  * of trits.
                     31:  *
                     32:  * @param octets               pointer to array of octets
                     33:  * @param num_trits            number of trits to produce
                     34:  * @param trits                        address for array of trits
                     35:  */
                     36: void ntru_bits_2_trits(uint8_t const *octets, uint16_t num_trits,
                     37:                                           uint8_t *trits);
                     38: 
                     39: /**
                     40:  * Each 2 trits in an array of trits is converted to 3 bits, and the bits
                     41:  * are packed in an array of octets.  A multiple of 3 octets is output.
                     42:  * Any bits in the final octets not derived from trits are zero.
                     43:  *
                     44:  * @param trits                                pointer to array of trits
                     45:  * @param num_trits                    number of trits to convert
                     46:  * @param octets                       address for array of octets
                     47:  * @return                                     TRUE if all trits were valid
                     48:  *                                     FALSE if invalid trits were found
                     49:  */
                     50: bool ntru_trits_2_bits(uint8_t const *trits, uint32_t num_trits,
                     51:                                           uint8_t *octets);
                     52: 
                     53: /**
                     54:  * Takes an array of coefficients mod 4 and packs the results into an
                     55:  * octet string.
                     56:  *
                     57:  * @param num_coeffs           number of coefficients
                     58:  * @param coeffs                       pointer to coefficients
                     59:  * @param octets                       address for octets
                     60:  */
                     61: void ntru_coeffs_mod4_2_octets(uint16_t num_coeffs, uint16_t const *coeffs,
                     62:                                                           uint8_t *octets);
                     63: 
                     64: /**
                     65:  * Packs 5 trits in an octet, where a trit is 0, 1, or 2 (-1).
                     66:  *
                     67:  * @param trits                                pointer to trits
                     68:  * @param octet                                address for octet
                     69:  */
                     70: void ntru_trits_2_octet(uint8_t const *trits, uint8_t *octet);
                     71: 
                     72: /**
                     73:  * Unpacks an octet to 5 trits, where a trit is 0, 1, or 2 (-1).
                     74:  *
                     75:  * @param octet                                octet to be unpacked
                     76:  * @param trits                                address for trits
                     77:  */
                     78: void ntru_octet_2_trits(uint8_t  octet, uint8_t *trits);
                     79: 
                     80: /**
                     81:  *
                     82:  * Converts a list of the nonzero indices of a polynomial into an array of
                     83:  * trits.
                     84:  *
                     85:  * @param in_len                       no. of indices
                     86:  * @param in                           pointer to list of indices
                     87:  * @param plus1                                if list is +1 coefficients
                     88:  * @param out                          address of output polynomial
                     89:  */
                     90: void ntru_indices_2_trits(uint16_t in_len, uint16_t const *in, bool plus1,
                     91:                                                  uint8_t *out);
                     92: 
                     93: /**
                     94:  * Unpacks an array of N trits and creates a list of array indices
                     95:  * corresponding to trits = +1, and list of array indices corresponding to
                     96:  * trits = -1.
                     97:  *
                     98:  * @param in                           pointer to packed-trit octets
                     99:  * @param num_trits                    no. of packed trits
                    100:  * @param indices_plus1                address for indices of +1 trits
                    101:  * @param indices_minus1       address for indices of -1 trits
                    102:  */
                    103: void ntru_packed_trits_2_indices(uint8_t const *in, uint16_t num_trits,
                    104:                                                                 uint16_t *indices_plus1,
                    105:                                                                 uint16_t *indices_minus1);
                    106: 
                    107: /**
                    108:  * Takes a list of array indices corresponding to elements whose values
                    109:  * are +1 or -1, and packs the N-element array of trits described by these
                    110:  * lists into octets, 5 trits per octet.
                    111:  *
                    112:  * @param indices                      pointer to indices
                    113:  * @param num_plus1                    no. of indices for +1 trits
                    114:  * @param num_minus1           no. of indices for -1 trits
                    115:  * @param num_trits                    N, no. of trits in array
                    116:  * @param buf                          temp buf, N octets
                    117:  * @param out                          address for packed octet
                    118:  */
                    119: void ntru_indices_2_packed_trits(uint16_t const *indices, uint16_t num_plus1,
                    120:                                                                 uint16_t num_minus1, uint16_t num_trits,
                    121:                                                                 uint8_t *buf, uint8_t *out);
                    122: 
                    123: /**
                    124:  * Packs an array of n-bit elements into an array of
                    125:  * ((in_len * n_bits) + 7) / 8 octets, 8 < n_bits < 16.
                    126:  *
                    127:  * @param in_len                       no. of elements to be packed
                    128:  * @param in                           ptr to elements to be packed
                    129:  * @param n_bits                       no. of bits in input element
                    130:  * @param out                          addr for output octets
                    131:  */
                    132: void ntru_elements_2_octets(uint16_t in_len, uint16_t const *in, uint8_t n_bits,
                    133:                                                        uint8_t *out);
                    134: 
                    135: /**
                    136:  * Unpacks an octet string into an array of ((in_len * 8) / n_bits)
                    137:  * n-bit elements, 8 < n < 16.  Any extra bits are discarded.
                    138:  *
                    139:  * @param in_len                       no. of octets to be unpacked
                    140:  * @param in                           ptr to octets to be unpacked
                    141:  * @param n_bits                       no. of bits in output element
                    142:  * @param out                          addr for output elements
                    143:  */
                    144: void ntru_octets_2_elements(uint16_t in_len, uint8_t const *in, uint8_t n_bits,
                    145:                                                        uint16_t *out);
                    146: 
                    147: #endif /** NTRU_CONVERT_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>