diff --git a/lib/crypto.c b/lib/crypto.c index 54f1a30..4752e0e 100644 --- a/lib/crypto.c +++ b/lib/crypto.c @@ -114,10 +114,16 @@ void aes_reset(aes_ctx_t *ctx, const EVP_CIPHER *type, aes_direction_t direction // AES CTR -aes_ctx_t *aes_ctr_init(const uint8_t *key, const uint8_t *iv) { +aes_ctx_t *aes_ctr_encrypt_init(const uint8_t *key, const uint8_t *iv) { return aes_init(key, iv, EVP_aes_128_ctr(), AES_ENCRYPT); } +aes_ctx_t *aes_ctr_decrypt_init(const uint8_t *key, const uint8_t *iv) { + return aes_init(key, iv, EVP_aes_128_ctr(), AES_DECRYPT); +} + + + void aes_ctr_encrypt(aes_ctx_t *ctx, const uint8_t *in, uint8_t *out, int len) { aes_encrypt(ctx, in, out, len); ctx->block_offset = (ctx->block_offset + len) % AES_128_BLOCK_SIZE; @@ -130,7 +136,7 @@ void aes_ctr_start_fresh_block(aes_ctx_t *ctx) { } void aes_ctr_decrypt(aes_ctx_t *ctx, const uint8_t *in, uint8_t *out, int len) { - aes_encrypt(ctx, in, out, len); + aes_decrypt(ctx, in, out, len); } void aes_ctr_reset(aes_ctx_t *ctx) { diff --git a/lib/crypto.h b/lib/crypto.h index 13c5f28..3f3a35a 100644 --- a/lib/crypto.h +++ b/lib/crypto.h @@ -41,7 +41,8 @@ typedef enum aes_direction_e { AES_DECRYPT, AES_ENCRYPT } aes_direction_t; typedef struct aes_ctx_s aes_ctx_t; -aes_ctx_t *aes_ctr_init(const uint8_t *key, const uint8_t *iv); +aes_ctx_t *aes_ctr_encrypt_init(const uint8_t *key, const uint8_t *iv); +aes_ctx_t *aes_ctr_decrypt_init(const uint8_t *key, const uint8_t *iv); void aes_ctr_reset(aes_ctx_t *ctx); void aes_ctr_encrypt(aes_ctx_t *ctx, const uint8_t *in, uint8_t *out, int len); void aes_ctr_decrypt(aes_ctx_t *ctx, const uint8_t *in, uint8_t *out, int len); diff --git a/lib/mirror_buffer.c b/lib/mirror_buffer.c index faaa800..84cd11d 100755 --- a/lib/mirror_buffer.c +++ b/lib/mirror_buffer.c @@ -77,7 +77,7 @@ mirror_buffer_init_aes(mirror_buffer_t *mirror_buffer, uint64_t streamConnection fclose(keyfile); #endif // Need to be initialized externally - mirror_buffer->aes_ctx = aes_ctr_init(decrypt_aeskey, decrypt_aesiv); + mirror_buffer->aes_ctx = aes_ctr_decrypt_init(decrypt_aeskey, decrypt_aesiv); mirror_buffer->nextDecryptCount = 0; } @@ -97,7 +97,6 @@ mirror_buffer_init(logger_t *logger, memcpy(mirror_buffer->ecdh_secret, ecdh_secret, 32); mirror_buffer->logger = logger; mirror_buffer->nextDecryptCount = 0; - //mirror_buffer_init_aes(mirror_buffer, aeskey, ecdh_secret, streamConnectionID); return mirror_buffer; } diff --git a/lib/pairing.c b/lib/pairing.c index 11ce287..db03c83 100755 --- a/lib/pairing.c +++ b/lib/pairing.c @@ -193,7 +193,7 @@ pairing_session_get_signature(pairing_session_t *session, unsigned char signatur derive_key_internal(session, (const unsigned char *) SALT_KEY, strlen(SALT_KEY), key, sizeof(key)); derive_key_internal(session, (const unsigned char *) SALT_IV, strlen(SALT_IV), iv, sizeof(iv)); - aes_ctx = aes_ctr_init(key, iv); + aes_ctx = aes_ctr_encrypt_init(key, iv); aes_ctr_encrypt(aes_ctx, signature, signature, PAIRING_SIG_SIZE); aes_ctr_destroy(aes_ctx); @@ -219,7 +219,7 @@ pairing_session_finish(pairing_session_t *session, const unsigned char signature derive_key_internal(session, (const unsigned char *) SALT_KEY, strlen(SALT_KEY), key, sizeof(key)); derive_key_internal(session, (const unsigned char *) SALT_IV, strlen(SALT_IV), iv, sizeof(iv)); - aes_ctx = aes_ctr_init(key, iv); + aes_ctx = aes_ctr_encrypt_init(key, iv); /* One fake round for the initial handshake encryption */ aes_ctr_encrypt(aes_ctx, sig_buffer, sig_buffer, PAIRING_SIG_SIZE); aes_ctr_encrypt(aes_ctx, signature, sig_buffer, PAIRING_SIG_SIZE);