diff options
author | fstrenzke <[email protected]> | 2014-11-26 18:19:47 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-11-26 18:19:47 +0000 |
commit | 0ef9ee80a015c7c88902cd435cff9e54c7db5dc1 (patch) | |
tree | 8a2461cd384fee3da5e9469721e013380b450443 /src/lib/pubkey/mce/code_based_util.h | |
parent | 2561eaf5c4794a97d2a2091b894d69e2c9f70c24 (diff) |
Add an implementation of McEliece encryption based on HyMES
(https://www.rocq.inria.fr/secret/CBCrypto/index.php?pg=hymes).
The original version is LGPL but cryptsource GmbH has secured
permission to release it under a BSD license. Also includes the
Overbeck CCA2 message encoding scheme.
Diffstat (limited to 'src/lib/pubkey/mce/code_based_util.h')
-rw-r--r-- | src/lib/pubkey/mce/code_based_util.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lib/pubkey/mce/code_based_util.h b/src/lib/pubkey/mce/code_based_util.h new file mode 100644 index 000000000..fd8bcaa49 --- /dev/null +++ b/src/lib/pubkey/mce/code_based_util.h @@ -0,0 +1,57 @@ +/** + * (C) Copyright Projet SECRET, INRIA, Rocquencourt + * (C) Bhaskar Biswas and Nicolas Sendrier + * + * (C) 2014 cryptosource GmbH + * (C) 2014 Falko Strenzke [email protected] + * + * Distributed under the terms of the Botan license + * + */ + +#ifndef BOTAN_CODE_BASED_UTIL_H__ +#define BOTAN_CODE_BASED_UTIL_H__ + +#include <botan/gf2m_small_m.h> + +namespace Botan { + +/** +* Expand an input to a bit mask depending on it being being zero or non-zero +* @ param tst the input +* @return the mask 0xFFFF if tst is non-zero and 0 otherwise +*/ +template<typename T> +u16bit expand_mask_16bit(T tst) + { + const u16bit result = (tst != 0); + return ~(result - 1); + } + +inline gf2m_small_m::gf2m gray_to_lex(gf2m_small_m::gf2m gray) + { + gf2m_small_m::gf2m result = gray ^ (gray>>8); + result ^= (result >> 4); + result ^= (result >> 2); + result ^= (result >> 1); + return result; + } + +inline gf2m_small_m::gf2m lex_to_gray(gf2m_small_m::gf2m lex) + { + return (lex>>1) ^ lex; + } + +inline u32bit bit_size_to_byte_size(u32bit bit_size) + { + return (bit_size - 1) / 8 + 1; + } + +inline u32bit bit_size_to_32bit_size(u32bit bit_size) + { + return (bit_size - 1) / 32 + 1; + } + +} + +#endif |