cryptonite 0.4 → 0.5
raw patch · 11 files changed
+110/−106 lines, 11 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- cbits/aes/generic.c +1/−1
- cbits/aes/gf.c +2/−2
- cbits/aes/gf.h +38/−38
- cbits/aes/x86ni.c +1/−1
- cbits/aes/x86ni.h +19/−19
- cbits/aes/x86ni_impl.c +9/−9
- cbits/cryptonite_aes.c +31/−31
- cbits/cryptonite_cpu.c +2/−2
- cbits/cryptonite_cpu.h +2/−2
- cryptonite.cabal +1/−1
CHANGELOG.md view
@@ -1,3 +1,7 @@+## 0.5++* Fix all strays exports to all be under the cryptonite prefix.+ ## 0.4 * Add a System DRG that represent a referentially transparent of evaluated bytes
cbits/aes/generic.c view
@@ -89,7 +89,7 @@ }; #define G(a,b,c,d,e,f) { a,b,c,d,e,f }-uint8_t gmtab[256][6] =+static uint8_t gmtab[256][6] = { G(0x00, 0x00, 0x00, 0x00, 0x00, 0x00), G(0x02, 0x03, 0x09, 0x0b, 0x0d, 0x0e), G(0x04, 0x06, 0x12, 0x16, 0x1a, 0x1c), G(0x06, 0x05, 0x1b, 0x1d, 0x17, 0x12),
cbits/aes/gf.c view
@@ -39,7 +39,7 @@ * to speed up the multiplication. * TODO: optimise with tables */-void gf_mul(block128 *a, block128 *b)+void cryptonite_gf_mul(block128 *a, block128 *b) { uint64_t a0, a1, v0, v1; int i, j;@@ -62,7 +62,7 @@ } /* inplace GFMUL for xts mode */-void gf_mulx(block128 *a)+void cryptonite_gf_mulx(block128 *a) { const uint64_t gf_mask = cpu_to_le64(0x8000000000000000ULL); uint64_t r = ((a->q[1] & gf_mask) ? cpu_to_le64(0x87) : 0);
cbits/aes/gf.h view
@@ -1,38 +1,38 @@-/* - * Copyright (c) 2012 Vincent Hanquez <vincent@snarc.org> - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of his contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#ifndef CRYPTONITE_AES_GF128MUL_H -#define CRYPTONITE_AES_GF128MUL_H - -#include "aes/block128.h" - -void gf_mul(block128 *a, block128 *b); -void gf_mulx(block128 *a); - -#endif +/*+ * Copyright (c) 2012 Vincent Hanquez <vincent@snarc.org>+ *+ * All rights reserved.+ *+ * Redistribution and use in source and binary forms, with or without+ * modification, are permitted provided that the following conditions+ * are met:+ * 1. Redistributions of source code must retain the above copyright+ * notice, this list of conditions and the following disclaimer.+ * 2. Redistributions in binary form must reproduce the above copyright+ * notice, this list of conditions and the following disclaimer in the+ * documentation and/or other materials provided with the distribution.+ * 3. Neither the name of the author nor the names of his contributors+ * may be used to endorse or promote products derived from this software+ * without specific prior written permission.+ *+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF+ * SUCH DAMAGE.+ */+#ifndef CRYPTONITE_AES_GF128MUL_H+#define CRYPTONITE_AES_GF128MUL_H++#include "aes/block128.h"++void cryptonite_gf_mul(block128 *a, block128 *b);+void cryptonite_gf_mulx(block128 *a);++#endif
cbits/aes/x86ni.c view
@@ -63,7 +63,7 @@ return _mm_xor_si128(key, keygened); } -void aes_ni_init(aes_key *key, uint8_t *ikey, uint8_t size)+void cryptonite_aesni_init(aes_key *key, uint8_t *ikey, uint8_t size) { __m128i k[28]; uint64_t *out = (uint64_t *) key->data;
cbits/aes/x86ni.h view
@@ -49,28 +49,28 @@ } #endif -void aes_ni_init(aes_key *key, uint8_t *origkey, uint8_t size);-void aes_ni_encrypt_block128(aes_block *out, aes_key *key, aes_block *in);-void aes_ni_encrypt_block256(aes_block *out, aes_key *key, aes_block *in);-void aes_ni_decrypt_block128(aes_block *out, aes_key *key, aes_block *in);-void aes_ni_decrypt_block256(aes_block *out, aes_key *key, aes_block *in);-void aes_ni_encrypt_ecb128(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks);-void aes_ni_encrypt_ecb256(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks);-void aes_ni_decrypt_ecb128(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks);-void aes_ni_decrypt_ecb256(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks);-void aes_ni_encrypt_cbc128(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks);-void aes_ni_encrypt_cbc256(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks);-void aes_ni_decrypt_cbc128(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks);-void aes_ni_decrypt_cbc256(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks);-void aes_ni_encrypt_ctr128(uint8_t *out, aes_key *key, aes_block *_iv, uint8_t *in, uint32_t length);-void aes_ni_encrypt_ctr256(uint8_t *out, aes_key *key, aes_block *_iv, uint8_t *in, uint32_t length);-void aes_ni_encrypt_xts128(aes_block *out, aes_key *key1, aes_key *key2,+void cryptonite_aesni_init(aes_key *key, uint8_t *origkey, uint8_t size);+void cryptonite_aesni_encrypt_block128(aes_block *out, aes_key *key, aes_block *in);+void cryptonite_aesni_encrypt_block256(aes_block *out, aes_key *key, aes_block *in);+void cryptonite_aesni_decrypt_block128(aes_block *out, aes_key *key, aes_block *in);+void cryptonite_aesni_decrypt_block256(aes_block *out, aes_key *key, aes_block *in);+void cryptonite_aesni_encrypt_ecb128(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks);+void cryptonite_aesni_encrypt_ecb256(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks);+void cryptonite_aesni_decrypt_ecb128(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks);+void cryptonite_aesni_decrypt_ecb256(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks);+void cryptonite_aesni_encrypt_cbc128(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks);+void cryptonite_aesni_encrypt_cbc256(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks);+void cryptonite_aesni_decrypt_cbc128(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks);+void cryptonite_aesni_decrypt_cbc256(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks);+void cryptonite_aesni_encrypt_ctr128(uint8_t *out, aes_key *key, aes_block *_iv, uint8_t *in, uint32_t length);+void cryptonite_aesni_encrypt_ctr256(uint8_t *out, aes_key *key, aes_block *_iv, uint8_t *in, uint32_t length);+void cryptonite_aesni_encrypt_xts128(aes_block *out, aes_key *key1, aes_key *key2, aes_block *_tweak, uint32_t spoint, aes_block *in, uint32_t blocks);-void aes_ni_encrypt_xts256(aes_block *out, aes_key *key1, aes_key *key2,+void cryptonite_aesni_encrypt_xts256(aes_block *out, aes_key *key1, aes_key *key2, aes_block *_tweak, uint32_t spoint, aes_block *in, uint32_t blocks); -void aes_ni_gcm_encrypt128(uint8_t *out, aes_gcm *gcm, aes_key *key, uint8_t *in, uint32_t length);-void aes_ni_gcm_encrypt256(uint8_t *out, aes_gcm *gcm, aes_key *key, uint8_t *in, uint32_t length);+void cryptonite_aesni_gcm_encrypt128(uint8_t *out, aes_gcm *gcm, aes_key *key, uint8_t *in, uint32_t length);+void cryptonite_aesni_gcm_encrypt256(uint8_t *out, aes_gcm *gcm, aes_key *key, uint8_t *in, uint32_t length); void gf_mul_x86ni(block128 *res, block128 *a_, block128 *b_);
cbits/aes/x86ni_impl.c view
@@ -28,7 +28,7 @@ * SUCH DAMAGE. */ -void SIZED(aes_ni_encrypt_block)(aes_block *out, aes_key *key, aes_block *in)+void SIZED(cryptonite_aesni_encrypt_block)(aes_block *out, aes_key *key, aes_block *in) { __m128i *k = (__m128i *) key->data; PRELOAD_ENC(k);@@ -37,7 +37,7 @@ _mm_storeu_si128((__m128i *) out, m); } -void SIZED(aes_ni_decrypt_block)(aes_block *out, aes_key *key, aes_block *in)+void SIZED(cryptonite_aesni_decrypt_block)(aes_block *out, aes_key *key, aes_block *in) { __m128i *k = (__m128i *) key->data; PRELOAD_DEC(k);@@ -46,7 +46,7 @@ _mm_storeu_si128((__m128i *) out, m); } -void SIZED(aes_ni_encrypt_ecb)(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks)+void SIZED(cryptonite_aesni_encrypt_ecb)(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks) { __m128i *k = (__m128i *) key->data; @@ -58,7 +58,7 @@ } } -void SIZED(aes_ni_decrypt_ecb)(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks)+void SIZED(cryptonite_aesni_decrypt_ecb)(aes_block *out, aes_key *key, aes_block *in, uint32_t blocks) { __m128i *k = (__m128i *) key->data; @@ -71,7 +71,7 @@ } } -void SIZED(aes_ni_encrypt_cbc)(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks)+void SIZED(cryptonite_aesni_encrypt_cbc)(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks) { __m128i *k = (__m128i *) key->data; __m128i iv = _mm_loadu_si128((__m128i *) _iv);@@ -87,7 +87,7 @@ } } -void SIZED(aes_ni_decrypt_cbc)(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks)+void SIZED(cryptonite_aesni_decrypt_cbc)(aes_block *out, aes_key *key, aes_block *_iv, aes_block *in, uint32_t blocks) { __m128i *k = (__m128i *) key->data; __m128i iv = _mm_loadu_si128((__m128i *) _iv);@@ -106,7 +106,7 @@ } } -void SIZED(aes_ni_encrypt_ctr)(uint8_t *output, aes_key *key, aes_block *_iv, uint8_t *input, uint32_t len)+void SIZED(cryptonite_aesni_encrypt_ctr)(uint8_t *output, aes_key *key, aes_block *_iv, uint8_t *input, uint32_t len) { __m128i *k = (__m128i *) key->data; __m128i bswap_mask = _mm_setr_epi8(7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8);@@ -151,7 +151,7 @@ return ; } -void SIZED(aes_ni_encrypt_xts)(aes_block *out, aes_key *key1, aes_key *key2,+void SIZED(cryptonite_aesni_encrypt_xts)(aes_block *out, aes_key *key1, aes_key *key2, aes_block *_tweak, uint32_t spoint, aes_block *in, uint32_t blocks) { __m128i tweak = _mm_loadu_si128((__m128i *) _tweak);@@ -181,7 +181,7 @@ } while (0); } -void SIZED(aes_ni_gcm_encrypt)(uint8_t *output, aes_gcm *gcm, aes_key *key, uint8_t *input, uint32_t length)+void SIZED(cryptonite_aesni_gcm_encrypt)(uint8_t *output, aes_gcm *gcm, aes_key *key, uint8_t *input, uint32_t length) { __m128i *k = (__m128i *) key->data; __m128i bswap_mask = _mm_setr_epi8(7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8);
cbits/cryptonite_aes.c view
@@ -191,36 +191,36 @@ { if (!aesni) return;- cryptonite_aes_branch_table[INIT_128] = aes_ni_init;- cryptonite_aes_branch_table[INIT_256] = aes_ni_init;+ cryptonite_aes_branch_table[INIT_128] = cryptonite_aesni_init;+ cryptonite_aes_branch_table[INIT_256] = cryptonite_aesni_init; - cryptonite_aes_branch_table[ENCRYPT_BLOCK_128] = aes_ni_encrypt_block128;- cryptonite_aes_branch_table[DECRYPT_BLOCK_128] = aes_ni_decrypt_block128;- cryptonite_aes_branch_table[ENCRYPT_BLOCK_256] = aes_ni_encrypt_block256;- cryptonite_aes_branch_table[DECRYPT_BLOCK_256] = aes_ni_decrypt_block256;+ cryptonite_aes_branch_table[ENCRYPT_BLOCK_128] = cryptonite_aesni_encrypt_block128;+ cryptonite_aes_branch_table[DECRYPT_BLOCK_128] = cryptonite_aesni_decrypt_block128;+ cryptonite_aes_branch_table[ENCRYPT_BLOCK_256] = cryptonite_aesni_encrypt_block256;+ cryptonite_aes_branch_table[DECRYPT_BLOCK_256] = cryptonite_aesni_decrypt_block256; /* ECB */- cryptonite_aes_branch_table[ENCRYPT_ECB_128] = aes_ni_encrypt_ecb128;- cryptonite_aes_branch_table[DECRYPT_ECB_128] = aes_ni_decrypt_ecb128;- cryptonite_aes_branch_table[ENCRYPT_ECB_256] = aes_ni_encrypt_ecb256;- cryptonite_aes_branch_table[DECRYPT_ECB_256] = aes_ni_decrypt_ecb256;+ cryptonite_aes_branch_table[ENCRYPT_ECB_128] = cryptonite_aesni_encrypt_ecb128;+ cryptonite_aes_branch_table[DECRYPT_ECB_128] = cryptonite_aesni_decrypt_ecb128;+ cryptonite_aes_branch_table[ENCRYPT_ECB_256] = cryptonite_aesni_encrypt_ecb256;+ cryptonite_aes_branch_table[DECRYPT_ECB_256] = cryptonite_aesni_decrypt_ecb256; /* CBC */- cryptonite_aes_branch_table[ENCRYPT_CBC_128] = aes_ni_encrypt_cbc128;- cryptonite_aes_branch_table[DECRYPT_CBC_128] = aes_ni_decrypt_cbc128;- cryptonite_aes_branch_table[ENCRYPT_CBC_256] = aes_ni_encrypt_cbc256;- cryptonite_aes_branch_table[DECRYPT_CBC_256] = aes_ni_decrypt_cbc256;+ cryptonite_aes_branch_table[ENCRYPT_CBC_128] = cryptonite_aesni_encrypt_cbc128;+ cryptonite_aes_branch_table[DECRYPT_CBC_128] = cryptonite_aesni_decrypt_cbc128;+ cryptonite_aes_branch_table[ENCRYPT_CBC_256] = cryptonite_aesni_encrypt_cbc256;+ cryptonite_aes_branch_table[DECRYPT_CBC_256] = cryptonite_aesni_decrypt_cbc256; /* CTR */- cryptonite_aes_branch_table[ENCRYPT_CTR_128] = aes_ni_encrypt_ctr128;- cryptonite_aes_branch_table[ENCRYPT_CTR_256] = aes_ni_encrypt_ctr256;+ cryptonite_aes_branch_table[ENCRYPT_CTR_128] = cryptonite_aesni_encrypt_ctr128;+ cryptonite_aes_branch_table[ENCRYPT_CTR_256] = cryptonite_aesni_encrypt_ctr256; /* XTS */- cryptonite_aes_branch_table[ENCRYPT_XTS_128] = aes_ni_encrypt_xts128;- cryptonite_aes_branch_table[ENCRYPT_XTS_256] = aes_ni_encrypt_xts256;+ cryptonite_aes_branch_table[ENCRYPT_XTS_128] = cryptonite_aesni_encrypt_xts128;+ cryptonite_aes_branch_table[ENCRYPT_XTS_256] = cryptonite_aesni_encrypt_xts256; /* GCM */- cryptonite_aes_branch_table[ENCRYPT_GCM_128] = aes_ni_gcm_encrypt128;- cryptonite_aes_branch_table[ENCRYPT_GCM_256] = aes_ni_gcm_encrypt256;+ cryptonite_aes_branch_table[ENCRYPT_GCM_128] = cryptonite_aesni_gcm_encrypt128;+ cryptonite_aes_branch_table[ENCRYPT_GCM_256] = cryptonite_aesni_gcm_encrypt256; /* OCB */ /*- cryptonite_aes_branch_table[ENCRYPT_OCB_128] = aes_ni_ocb_encrypt128;- cryptonite_aes_branch_table[ENCRYPT_OCB_256] = aes_ni_ocb_encrypt256;+ cryptonite_aes_branch_table[ENCRYPT_OCB_128] = cryptonite_aesni_ocb_encrypt128;+ cryptonite_aes_branch_table[ENCRYPT_OCB_256] = cryptonite_aesni_ocb_encrypt256; */ } #endif@@ -233,7 +233,7 @@ case 32: key->nbr = 14; key->strength = 2; break; } #if defined(ARCH_X86) && defined(WITH_AESNI)- initialize_hw(initialize_table_ni);+ cryptonite_aesni_initialize_hw(initialize_table_ni); #endif init_f _init = GET_INIT(key->strength); _init(key, origkey, size);@@ -336,7 +336,7 @@ static void gcm_ghash_add(aes_gcm *gcm, block128 *b) { block128_xor(&gcm->tag, b);- gf_mul(&gcm->tag, &gcm->h);+ cryptonite_gf_mul(&gcm->tag, &gcm->h); } void cryptonite_aes_gcm_init(aes_gcm *gcm, aes_key *key, uint8_t *iv, uint32_t len)@@ -359,15 +359,15 @@ int i; for (; len >= 16; len -= 16, iv += 16) { block128_xor(&gcm->iv, (block128 *) iv);- gf_mul(&gcm->iv, &gcm->h);+ cryptonite_gf_mul(&gcm->iv, &gcm->h); } if (len > 0) { block128_xor_bytes(&gcm->iv, iv, len);- gf_mul(&gcm->iv, &gcm->h);+ cryptonite_gf_mul(&gcm->iv, &gcm->h); } for (i = 15; origlen; --i, origlen >>= 8) gcm->iv.b[i] ^= (uint8_t) origlen;- gf_mul(&gcm->iv, &gcm->h);+ cryptonite_gf_mul(&gcm->iv, &gcm->h); } block128_copy(&gcm->civ, &gcm->iv);@@ -596,9 +596,9 @@ /* TO OPTIMISE: this is really inefficient way to do that */ while (spoint-- > 0)- gf_mulx(&tweak);+ cryptonite_gf_mulx(&tweak); - for ( ; nb_blocks-- > 0; input++, output++, gf_mulx(&tweak)) {+ for ( ; nb_blocks-- > 0; input++, output++, cryptonite_gf_mulx(&tweak)) { block128_vxor(&block, input, &tweak); cryptonite_aes_encrypt_block(&block, k1, &block); block128_vxor(output, &block, &tweak);@@ -616,9 +616,9 @@ /* TO OPTIMISE: this is really inefficient way to do that */ while (spoint-- > 0)- gf_mulx(&tweak);+ cryptonite_gf_mulx(&tweak); - for ( ; nb_blocks-- > 0; input++, output++, gf_mulx(&tweak)) {+ for ( ; nb_blocks-- > 0; input++, output++, cryptonite_gf_mulx(&tweak)) { block128_vxor(&block, input, &tweak); cryptonite_aes_decrypt_block(&block, k1, &block); block128_vxor(output, &block, &tweak);
cbits/cryptonite_cpu.c view
@@ -54,7 +54,7 @@ } #ifdef USE_AESNI-void initialize_hw(void (*init_table)(int, int))+void cryptonite_aesni_initialize_hw(void (*init_table)(int, int)) { static int inited = 0; if (inited == 0) {@@ -69,7 +69,7 @@ } } #else-#define initialize_hw(init_table) (0)+#define cryptonite_aesni_initialize_hw(init_table) (0) #endif #endif
cbits/cryptonite_cpu.h view
@@ -37,9 +37,9 @@ #endif #ifdef USE_AESNI-void initialize_hw(void (*init_table)(int, int));+void cryptonite_aesni_initialize_hw(void (*init_table)(int, int)); #else-#define initialize_hw(init_table) (0)+#define cryptonite_aesni_initialize_hw(init_table) (0) #endif #endif
cryptonite.cabal view
@@ -1,5 +1,5 @@ Name: cryptonite-Version: 0.4+Version: 0.5 Synopsis: Cryptography Primitives sink Description: A repository of cryptographic primitives.