From 38ef16bcdfbc091503e246dfbcc159e0f29f4ad0 Mon Sep 17 00:00:00 2001 From: bol-van Date: Sun, 23 Nov 2025 13:34:27 +0300 Subject: [PATCH] nfqws2: update crypto --- nfq2/crypto/aes-ctr.c | 17 +++++++++++++++-- nfq2/crypto/aes-ctr.h | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/nfq2/crypto/aes-ctr.c b/nfq2/crypto/aes-ctr.c index 484e072..dc37fe1 100644 --- a/nfq2/crypto/aes-ctr.c +++ b/nfq2/crypto/aes-ctr.c @@ -3,7 +3,7 @@ #define AES_BLOCKLEN 16 -void aes_ctr_xcrypt_buffer(aes_context *ctx, const uint8_t *iv, uint8_t *buf, size_t length) +void aes_ctr_xcrypt_buffer(aes_context *ctx, const uint8_t *iv, const uint8_t *in, size_t length, uint8_t *out) { uint8_t bi, buffer[AES_BLOCKLEN], ivc[AES_BLOCKLEN]; size_t i; @@ -31,6 +31,19 @@ void aes_ctr_xcrypt_buffer(aes_context *ctx, const uint8_t *iv, uint8_t *buf, si } bi = 0; } - buf[i] = (buf[i] ^ buffer[bi]); + out[i] = in[i] ^ buffer[bi]; } } + +int aes_ctr_crypt(const uint8_t *key, const size_t key_len, const uint8_t *iv, const uint8_t *in, size_t length, uint8_t *out) +{ + int ret=0; + aes_context ctx; + + aes_init_keygen_tables(); + + if (!(ret=aes_setkey(&ctx, AES_ENCRYPT, key, key_len))) + aes_ctr_xcrypt_buffer(&ctx, iv, in, length, out); + + return ret; +} diff --git a/nfq2/crypto/aes-ctr.h b/nfq2/crypto/aes-ctr.h index db38f39..107ca0f 100644 --- a/nfq2/crypto/aes-ctr.h +++ b/nfq2/crypto/aes-ctr.h @@ -3,5 +3,5 @@ #include #include "aes.h" -// this function rewrites buf -void aes_ctr_xcrypt_buffer(aes_context *ctx, const uint8_t *iv, uint8_t *buf, size_t length); +void aes_ctr_xcrypt_buffer(aes_context *ctx, const uint8_t *iv, const uint8_t *in, size_t length, uint8_t *out); +int aes_ctr_crypt(const uint8_t *key, const size_t key_len, const uint8_t *iv, const uint8_t *in, size_t length, uint8_t *out);