From: Maksym Mamontov Date: Fri, 22 Jul 2022 19:38:27 +0000 (+0300) Subject: Cryptography with void* in the interfaces. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/38f134e6a96c08fdd7d4ed07ca3550e8434d56e9?hp=479b8853c2ab18c98926a9369a03888021e9b986 Cryptography with void* in the interfaces. --- diff --git a/libs/crypto/blowfish.c b/libs/crypto/blowfish.c index 384d3a10..42b9158a 100644 --- a/libs/crypto/blowfish.c +++ b/libs/crypto/blowfish.c @@ -384,10 +384,11 @@ Xl = Xl ^ ctx->P[0]; *xr = Xr; } //----------------------------------------------------------------------------- -void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen) +void Blowfish_Init(BLOWFISH_CTX *ctx, void* key, int keyLen) { int i, j, k; uint32_t data, datal, datar; +unsigned char* keyPtr = key; memset(ctx->S, 0, sizeof(ctx->S)); @@ -406,7 +407,7 @@ for (i = 0; i < N + 2; ++i) for (k = 0; k < 4; ++k) { - data = (data << 8) | key[j]; + data = (data << 8) | keyPtr[j]; j = j + 1; if (j >= keyLen) j = 0; diff --git a/libs/crypto/include/stg/blowfish.h b/libs/crypto/include/stg/blowfish.h index 6a4e6f31..101b2f6f 100644 --- a/libs/crypto/include/stg/blowfish.h +++ b/libs/crypto/include/stg/blowfish.h @@ -24,7 +24,7 @@ typedef struct { uint32_t S[4][256]; } BLOWFISH_CTX; -void Blowfish_Init(BLOWFISH_CTX * ctx, unsigned char * key, int keyLen); +void Blowfish_Init(BLOWFISH_CTX * ctx, void* key, int keyLen); void Blowfish_Encrypt(const BLOWFISH_CTX * ctx, uint32_t * xl, uint32_t * xr); void Blowfish_Decrypt(const BLOWFISH_CTX * ctx, uint32_t * xl, uint32_t * xr);