diff options
author | Dave Airlie <airlied@redhat.com> | 2014-11-04 13:02:05 +1000 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2014-11-04 13:02:05 +1000 |
commit | de262e144187ba83fb8f02357d6d3bb2622f68ae (patch) | |
tree | 623b93af25ded76f34b2b4b112dfc48f8383a497 | |
parent | 87919bc43fe09bbdebbb3601f47334a885a0886a (diff) |
consolidate aes ctr code
-rw-r--r-- | dl3.c | 48 |
1 files changed, 14 insertions, 34 deletions
@@ -123,22 +123,21 @@ static int create_gcrypt_km(gcry_sexp_t *km, #define NULL_BYTES \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -static void calculate_kd(struct hdcp_session_info *info) +static void calc_kd_ctr(struct hdcp_session_info *info, uint8_t ctr, + uint8_t *buf) { - uint8_t *buf; + uint8_t tmp[100]; unsigned char input[] = {NULL_BYTES, NULL_BYTES}; uint8_t iv[16]; - uint8_t tmp[100]; int outl; int ret; - buf = info->kd; - memset(buf, 0, KD_SIZE); - memset(iv, 0, 16); memcpy(iv, info->rtx, 8); + iv[sizeof(iv)-1] = ctr; /* iv is now r_tx|ctr */ + ret = EVP_EncryptInit_ex(&info->aes_ctx, EVP_aes_128_ctr(), NULL, info->km, iv); assert(ret == 1); @@ -150,20 +149,16 @@ static void calculate_kd(struct hdcp_session_info *info) assert(ret == 1); assert(outl == 0); - iv[sizeof(iv)-1] = 0x01; /* iv is now r_tx|0...01 */ - - ret = EVP_EncryptInit_ex(&info->aes_ctx, EVP_aes_128_ctr(), NULL, info->km, iv); - assert(ret == 1); +} +static void calculate_kd(struct hdcp_session_info *info) +{ + uint8_t *buf; + buf = info->kd; + memset(buf, 0, KD_SIZE); - ret = EVP_EncryptUpdate(&info->aes_ctx, &buf[16], &outl, input, sizeof(input)); - assert(ret == 1); - assert(outl == sizeof(input)); + calc_kd_ctr(info, 0, buf); - ret = EVP_EncryptFinal_ex(&info->aes_ctx, tmp, &outl); - assert(ret == 1); - assert(outl == 0); - - assert(ret == 1); + calc_kd_ctr(info, 1, &buf[16]); } static void calculate_edkey_ks(struct hdcp_session_info *info) @@ -176,22 +171,7 @@ static void calculate_edkey_ks(struct hdcp_session_info *info) uint8_t tmp[100]; int i; - memset(iv, 0, 16); - - memcpy(iv, info->rtx, 8); - - iv[sizeof(iv)-1] = 0x02; /* iv is now r_tx|0...02 */ - - ret = EVP_EncryptInit_ex(&info->aes_ctx, EVP_aes_128_ctr(), NULL, info->km, iv); - assert(ret == 1); - - ret = EVP_EncryptUpdate(&info->aes_ctx, buf, &outl, input, sizeof(input)); - assert(ret == 1); - assert(outl == sizeof(input)); - - ret = EVP_EncryptFinal_ex(&info->aes_ctx, tmp, &outl); - assert(ret == 1); - assert(outl == 0); + calc_kd_ctr(info, 2, buf); /* we have dkey2 in buf now */ printf("dkey2:"); |