aes/hmac: apple crypto fixes
This commit is contained in:
parent
086ae1d4f4
commit
3e997ac54d
2 changed files with 9 additions and 4 deletions
|
@ -83,6 +83,11 @@ void aes_set_iv(struct aes *st, const uint8_t iv[AES_BLOCK_SIZE])
|
|||
return;
|
||||
|
||||
/* we must reset the state when updating IV */
|
||||
if (st->cryptor) {
|
||||
CCCryptorRelease(st->cryptor);
|
||||
st->cryptor = NULL;
|
||||
}
|
||||
|
||||
status = CCCryptorCreateWithMode(kCCEncrypt, kCCModeCTR,
|
||||
kCCAlgorithmAES, ccNoPadding,
|
||||
iv, st->key, st->key_bytes,
|
||||
|
|
|
@ -12,9 +12,11 @@
|
|||
#include <re_hmac.h>
|
||||
|
||||
|
||||
enum { KEY_SIZE = 20 };
|
||||
|
||||
struct hmac {
|
||||
CCHmacContext ctx;
|
||||
uint8_t key[20];
|
||||
uint8_t key[KEY_SIZE];
|
||||
size_t key_len;
|
||||
};
|
||||
|
||||
|
@ -32,7 +34,7 @@ int hmac_create(struct hmac **hmacp, enum hmac_hash hash,
|
|||
{
|
||||
struct hmac *hmac;
|
||||
|
||||
if (!hmacp || !key || !key_len)
|
||||
if (!hmacp || !key || !key_len || key_len > KEY_SIZE)
|
||||
return EINVAL;
|
||||
|
||||
if (hash != HMAC_HASH_SHA1)
|
||||
|
@ -45,8 +47,6 @@ int hmac_create(struct hmac **hmacp, enum hmac_hash hash,
|
|||
memcpy(hmac->key, key, key_len);
|
||||
hmac->key_len = key_len;
|
||||
|
||||
CCHmacInit(&hmac->ctx, kCCHmacAlgSHA1, key, key_len);
|
||||
|
||||
*hmacp = hmac;
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue