Changeset View
Changeset View
Standalone View
Standalone View
sys/crypto/aesni/aesni_ccm.c
Show First 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
static const int tag_length = 16; /* 128 bits */ | static const int tag_length = 16; /* 128 bits */ | ||||
int L; | int L; | ||||
int counter = 1; /* S0 has 0, S1 has 1 */ | int counter = 1; /* S0 has 0, S1 has 1 */ | ||||
size_t copy_amt, total = 0; | size_t copy_amt, total = 0; | ||||
uint8_t *byte_ptr; | uint8_t *byte_ptr; | ||||
__m128i s0, rolling_mac, s_x, staging_block; | __m128i s0, rolling_mac, s_x, staging_block; | ||||
if (nbytes == 0 && abytes == 0) | |||||
return; | |||||
/* NIST 800-38c section A.1 says n is [7, 13]. */ | /* NIST 800-38c section A.1 says n is [7, 13]. */ | ||||
if (nlen < 7 || nlen > 13) | if (nlen < 7 || nlen > 13) | ||||
panic("%s: bad nonce length %d", __FUNCTION__, nlen); | panic("%s: bad nonce length %d", __FUNCTION__, nlen); | ||||
/* | /* | ||||
* We need to know how many bytes to use to describe | * We need to know how many bytes to use to describe | ||||
* the length of the data. Normally, nlen should be | * the length of the data. Normally, nlen should be | ||||
* 12, which leaves us 3 bytes to do that -- 16mbytes of | * 12, which leaves us 3 bytes to do that -- 16mbytes of | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | AES_CCM_decrypt(const unsigned char *in, unsigned char *out, | ||||
const unsigned char *tag, uint32_t nbytes, uint32_t abytes, int nlen, | const unsigned char *tag, uint32_t nbytes, uint32_t abytes, int nlen, | ||||
const unsigned char *key, int nr) | const unsigned char *key, int nr) | ||||
{ | { | ||||
static const int tag_length = 16; /* 128 bits */ | static const int tag_length = 16; /* 128 bits */ | ||||
int L; | int L; | ||||
__m128i s0, rolling_mac, staging_block; | __m128i s0, rolling_mac, staging_block; | ||||
uint8_t *byte_ptr; | uint8_t *byte_ptr; | ||||
if (nbytes == 0 && abytes == 0) | |||||
return (1); // No message means no decryption! | |||||
if (nlen < 0 || nlen > 15) | if (nlen < 0 || nlen > 15) | ||||
panic("%s: bad nonce length %d", __FUNCTION__, nlen); | panic("%s: bad nonce length %d", __FUNCTION__, nlen); | ||||
/* | /* | ||||
* We need to know how many bytes to use to describe | * We need to know how many bytes to use to describe | ||||
* the length of the data. Normally, nlen should be | * the length of the data. Normally, nlen should be | ||||
* 12, which leaves us 3 bytes to do that -- 16mbytes of | * 12, which leaves us 3 bytes to do that -- 16mbytes of | ||||
* data to encrypt. But it can be longer or shorter. | * data to encrypt. But it can be longer or shorter. | ||||
Show All 34 Lines |