diff --git a/cbits/aes/x86ni.c b/cbits/aes/x86ni.c index a881fda..a639fab 100644 --- a/cbits/aes/x86ni.c +++ b/cbits/aes/x86ni.c @@ -63,7 +63,7 @@ static __m128i aes_128_key_expansion_aa(__m128i key, __m128i keygened) 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; diff --git a/cbits/aes/x86ni.h b/cbits/aes/x86ni.h index 1232c97..f71ee0f 100644 --- a/cbits/aes/x86ni.h +++ b/cbits/aes/x86ni.h @@ -49,28 +49,28 @@ static void block128_sse_print(__m128i m) } #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_); diff --git a/cbits/aes/x86ni_impl.c b/cbits/aes/x86ni_impl.c index f28745a..d019a2a 100644 --- a/cbits/aes/x86ni_impl.c +++ b/cbits/aes/x86ni_impl.c @@ -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 @@ void SIZED(aes_ni_encrypt_block)(aes_block *out, aes_key *key, aes_block *in) _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 @@ void SIZED(aes_ni_decrypt_block)(aes_block *out, aes_key *key, aes_block *in) _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_encrypt_ecb)(aes_block *out, aes_key *key, aes_block *in, uint } } -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_decrypt_ecb)(aes_block *out, aes_key *key, aes_block *in, uint } } -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_encrypt_cbc)(aes_block *out, aes_key *key, aes_block *_iv, aes } } -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_decrypt_cbc)(aes_block *out, aes_key *key, aes_block *_iv, aes } } -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 @@ void SIZED(aes_ni_encrypt_ctr)(uint8_t *output, aes_key *key, aes_block *_iv, ui 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 @@ void SIZED(aes_ni_encrypt_xts)(aes_block *out, aes_key *key1, aes_key *key2, } 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); diff --git a/cbits/cryptonite_aes.c b/cbits/cryptonite_aes.c index 12d3164..a4bde96 100644 --- a/cbits/cryptonite_aes.c +++ b/cbits/cryptonite_aes.c @@ -191,36 +191,36 @@ static void initialize_table_ni(int aesni, int pclmul) { 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