Clean up in crypto.c, (but doesnt fix the OpenSSL 3.0.0 problem)

This commit is contained in:
fduncanh
2021-10-11 04:41:52 -04:00
parent e6b611cbdd
commit 8425159981
4 changed files with 13 additions and 7 deletions

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);