2 * transsip - the telephony toolkit
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>
5 * Subject to the GPL, version 2.
6 * Based on Bhaskar Biswas and Nicolas Sendrier McEliece
7 * implementation, LGPL 2.1.
18 #define NB_ERRORS ERROR_WEIGHT
19 #define EXT_DEGREE LOG_LENGTH
21 #define LENGTH (1 << EXT_DEGREE)
22 #define CODIMENSION (NB_ERRORS * EXT_DEGREE)
23 #define DIMENSION (LENGTH - CODIMENSION)
25 /* number of bytes needed for storing nb_bits bits */
26 #define BITS_TO_BYTES(nb_bits) (((nb_bits) - 1) / 8 + 1)
28 /* number bits in one long */
29 #define BIT_SIZE_OF_LONG (8 * sizeof(uint32_t))
31 /* number of long needed for storing nb_bits bits */
32 #define BITS_TO_LONG(nb_bits) (((nb_bits) - 1) / BIT_SIZE_OF_LONG + 1)
34 #define SECRETKEY_BYTES (LENGTH * sizeof(uint32_t) * \
35 BITS_TO_LONG(CODIMENSION) + \
36 (LENGTH + 1 + (NB_ERRORS + 1) * \
37 NB_ERRORS) * sizeof(gf16_t))
39 #define PUBLICKEY_BYTES (BITS_TO_LONG(CODIMENSION) * \
40 sizeof(uint32_t) * DIMENSION)
42 #define CLEARTEXT_LENGTH (DIMENSION + ERROR_SIZE)
43 #define CLEARTEXT_BYTES BITS_TO_BYTES(CLEARTEXT_LENGTH)
44 #define CIPHERTEXT_BYTES BITS_TO_BYTES(LENGTH)
47 * CLEARTEXT_BYTES is the number of bytes of the block to be encrypted
48 * (= CLEARTEXT_LENGTH / 8 rounded up)
50 * MESSAGE_BYTES is the number of information bytes in each block
51 * (= CLEARTEXT_LENGTH / 8 rounded down possibly one less than
54 * To add a semantically secure conversion, one can reduce
55 * MESSAGE_BYTES accordingly and add a randomization layer before
56 * encryption (and after decryption)
59 #define MESSAGE_BYTES (CLEARTEXT_LENGTH / 8)