Skip to content

Commit f26c713

Browse files
committed
prefix macros in tls_aes128
1 parent 05e5533 commit f26c713

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

mongoose.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8512,9 +8512,9 @@ int aes_setkey(aes_context *ctx, // AES context provided by our caller
85128512
}
85138513

85148514
#if AES_DECRYPTION
8515-
if (mode == DECRYPT) // expand our key for encryption or decryption
8515+
if (mode == MG_DECRYPT) // expand our key for encryption or decryption
85168516
return (aes_set_decryption_key(ctx, key, keysize));
8517-
else /* ENCRYPT */
8517+
else /* MG_ENCRYPT */
85188518
#endif /* AES_DECRYPTION */
85198519
return (aes_set_encryption_key(ctx, key, keysize));
85208520
}
@@ -8545,7 +8545,7 @@ int aes_cipher(aes_context *ctx, const uchar input[16], uchar output[16]) {
85458545

85468546
#if AES_DECRYPTION // whether AES decryption is supported
85478547

8548-
if (ctx->mode == DECRYPT) {
8548+
if (ctx->mode == MG_DECRYPT) {
85498549
for (i = (ctx->rounds >> 1) - 1; i > 0; i--) {
85508550
AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3);
85518551
AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3);
@@ -8572,7 +8572,7 @@ int aes_cipher(aes_context *ctx, const uchar input[16], uchar output[16]) {
85728572
((uint32_t) RSb[(Y2 >> 8) & 0xFF] << 8) ^
85738573
((uint32_t) RSb[(Y1 >> 16) & 0xFF] << 16) ^
85748574
((uint32_t) RSb[(Y0 >> 24) & 0xFF] << 24);
8575-
} else /* ENCRYPT */
8575+
} else /* MG_ENCRYPT */
85768576
{
85778577
#endif /* AES_DECRYPTION */
85788578

@@ -8799,7 +8799,7 @@ int gcm_setkey(gcm_context *ctx, // pointer to caller-provided gcm context
87998799

88008800
// encrypt the null 128-bit block to generate a key-based value
88018801
// which is then used to initialize our GHASH lookup tables
8802-
if ((ret = aes_setkey(&ctx->aes_ctx, ENCRYPT, key, keysize)) != 0)
8802+
if ((ret = aes_setkey(&ctx->aes_ctx, MG_ENCRYPT, key, keysize)) != 0)
88038803
return (ret);
88048804
if ((ret = aes_cipher(&ctx->aes_ctx, h, h)) != 0) return (ret);
88058805

@@ -8877,7 +8877,7 @@ int gcm_start(gcm_context *ctx, // pointer to user-provided GCM context
88778877
ctx->add_len = 0;
88788878

88798879
ctx->mode = mode; // set the GCM encryption/decryption mode
8880-
ctx->aes_ctx.mode = ENCRYPT; // GCM *always* runs AES in ENCRYPTION mode
8880+
ctx->aes_ctx.mode = MG_ENCRYPT; // GCM *always* runs AES in ENCRYPTION mode
88818881

88828882
if (iv_len == 12) { // GCM natively uses a 12-byte, 96-bit IV
88838883
memcpy(ctx->y, iv, iv_len); // copy the IV to the top of the 'y' buff
@@ -8948,7 +8948,7 @@ int gcm_update(gcm_context *ctx, // pointer to user-provided GCM context
89488948
if ((ret = aes_cipher(&ctx->aes_ctx, ctx->y, ectr)) != 0) return (ret);
89498949

89508950
// encrypt or decrypt the input to the output
8951-
if (ctx->mode == ENCRYPT) {
8951+
if (ctx->mode == MG_ENCRYPT) {
89528952
for (i = 0; i < use_len; i++) {
89538953
// XOR the cipher's ouptut vector (ectr) with our input
89548954
output[i] = (uchar) (ectr[i] ^ input[i]);
@@ -9086,7 +9086,7 @@ int gcm_auth_decrypt(
90869086
(which is an identical XORing to reverse the previous one)
90879087
and also to re-generate the matching authentication tag
90889088
*/
9089-
gcm_crypt_and_tag(ctx, DECRYPT, iv, iv_len, add, add_len, input, output,
9089+
gcm_crypt_and_tag(ctx, MG_DECRYPT, iv, iv_len, add, add_len, input, output,
90909090
length, check_tag, tag_len);
90919091

90929092
// now we verify the authentication tag in 'constant time'
@@ -9131,7 +9131,7 @@ int aes_gcm_encrypt(unsigned char *output, //
91319131

91329132
gcm_setkey(&ctx, key, (const uint) key_len);
91339133

9134-
ret = gcm_crypt_and_tag(&ctx, ENCRYPT, iv, iv_len, aead, aead_len, input, output,
9134+
ret = gcm_crypt_and_tag(&ctx, MG_ENCRYPT, iv, iv_len, aead, aead_len, input, output,
91359135
input_length, tag, tag_len);
91369136

91379137
gcm_zero_ctx(&ctx);
@@ -9151,7 +9151,7 @@ int aes_gcm_decrypt(unsigned char *output, const unsigned char *input,
91519151

91529152
gcm_setkey(&ctx, key, (const uint) key_len);
91539153

9154-
ret = gcm_crypt_and_tag(&ctx, DECRYPT, iv, iv_len, NULL, 0, input, output,
9154+
ret = gcm_crypt_and_tag(&ctx, MG_DECRYPT, iv, iv_len, NULL, 0, input, output,
91559155
input_length, tag_buf, tag_len);
91569156

91579157
gcm_zero_ctx(&ctx);

mongoose.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,8 +1220,8 @@ void mg_hmac_sha256(uint8_t dst[32], uint8_t *key, size_t keysz, uint8_t *data,
12201220
#define AES_DECRYPTION 1 // whether AES decryption is supported
12211221
/******************************************************************************/
12221222

1223-
#define ENCRYPT 1 // specify whether we're encrypting
1224-
#define DECRYPT 0 // or decrypting
1223+
#define MG_ENCRYPT 1 // specify whether we're encrypting
1224+
#define MG_DECRYPT 0 // or decrypting
12251225

12261226

12271227

@@ -1339,7 +1339,7 @@ int gcm_setkey(gcm_context *ctx, // caller-provided context ptr
13391339
******************************************************************************/
13401340
int gcm_crypt_and_tag(
13411341
gcm_context *ctx, // gcm context with key already setup
1342-
int mode, // cipher direction: ENCRYPT (1) or DECRYPT (0)
1342+
int mode, // cipher direction: MG_ENCRYPT (1) or MG_DECRYPT (0)
13431343
const uchar *iv, // pointer to the 12-byte initialization vector
13441344
size_t iv_len, // byte length if the IV. should always be 12
13451345
const uchar *add, // pointer to the non-ciphered additional data
@@ -1384,7 +1384,7 @@ int gcm_auth_decrypt(
13841384
******************************************************************************/
13851385
int gcm_start(
13861386
gcm_context *ctx, // pointer to user-provided GCM context
1387-
int mode, // ENCRYPT (1) or DECRYPT (0)
1387+
int mode, // MG_ENCRYPT (1) or MG_DECRYPT (0)
13881388
const uchar *iv, // pointer to initialization vector
13891389
size_t iv_len, // IV length in bytes (should == 12)
13901390
const uchar *add, // pointer to additional AEAD data (NULL if none)

src/tls_aes128.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ int aes_setkey(aes_context *ctx, // AES context provided by our caller
353353
}
354354

355355
#if AES_DECRYPTION
356-
if (mode == DECRYPT) // expand our key for encryption or decryption
356+
if (mode == MG_DECRYPT) // expand our key for encryption or decryption
357357
return (aes_set_decryption_key(ctx, key, keysize));
358-
else /* ENCRYPT */
358+
else /* MG_ENCRYPT */
359359
#endif /* AES_DECRYPTION */
360360
return (aes_set_encryption_key(ctx, key, keysize));
361361
}
@@ -386,7 +386,7 @@ int aes_cipher(aes_context *ctx, const uchar input[16], uchar output[16]) {
386386

387387
#if AES_DECRYPTION // whether AES decryption is supported
388388

389-
if (ctx->mode == DECRYPT) {
389+
if (ctx->mode == MG_DECRYPT) {
390390
for (i = (ctx->rounds >> 1) - 1; i > 0; i--) {
391391
AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3);
392392
AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3);
@@ -413,7 +413,7 @@ int aes_cipher(aes_context *ctx, const uchar input[16], uchar output[16]) {
413413
((uint32_t) RSb[(Y2 >> 8) & 0xFF] << 8) ^
414414
((uint32_t) RSb[(Y1 >> 16) & 0xFF] << 16) ^
415415
((uint32_t) RSb[(Y0 >> 24) & 0xFF] << 24);
416-
} else /* ENCRYPT */
416+
} else /* MG_ENCRYPT */
417417
{
418418
#endif /* AES_DECRYPTION */
419419

@@ -640,7 +640,7 @@ int gcm_setkey(gcm_context *ctx, // pointer to caller-provided gcm context
640640

641641
// encrypt the null 128-bit block to generate a key-based value
642642
// which is then used to initialize our GHASH lookup tables
643-
if ((ret = aes_setkey(&ctx->aes_ctx, ENCRYPT, key, keysize)) != 0)
643+
if ((ret = aes_setkey(&ctx->aes_ctx, MG_ENCRYPT, key, keysize)) != 0)
644644
return (ret);
645645
if ((ret = aes_cipher(&ctx->aes_ctx, h, h)) != 0) return (ret);
646646

@@ -718,7 +718,7 @@ int gcm_start(gcm_context *ctx, // pointer to user-provided GCM context
718718
ctx->add_len = 0;
719719

720720
ctx->mode = mode; // set the GCM encryption/decryption mode
721-
ctx->aes_ctx.mode = ENCRYPT; // GCM *always* runs AES in ENCRYPTION mode
721+
ctx->aes_ctx.mode = MG_ENCRYPT; // GCM *always* runs AES in ENCRYPTION mode
722722

723723
if (iv_len == 12) { // GCM natively uses a 12-byte, 96-bit IV
724724
memcpy(ctx->y, iv, iv_len); // copy the IV to the top of the 'y' buff
@@ -789,7 +789,7 @@ int gcm_update(gcm_context *ctx, // pointer to user-provided GCM context
789789
if ((ret = aes_cipher(&ctx->aes_ctx, ctx->y, ectr)) != 0) return (ret);
790790

791791
// encrypt or decrypt the input to the output
792-
if (ctx->mode == ENCRYPT) {
792+
if (ctx->mode == MG_ENCRYPT) {
793793
for (i = 0; i < use_len; i++) {
794794
// XOR the cipher's ouptut vector (ectr) with our input
795795
output[i] = (uchar) (ectr[i] ^ input[i]);
@@ -927,7 +927,7 @@ int gcm_auth_decrypt(
927927
(which is an identical XORing to reverse the previous one)
928928
and also to re-generate the matching authentication tag
929929
*/
930-
gcm_crypt_and_tag(ctx, DECRYPT, iv, iv_len, add, add_len, input, output,
930+
gcm_crypt_and_tag(ctx, MG_DECRYPT, iv, iv_len, add, add_len, input, output,
931931
length, check_tag, tag_len);
932932

933933
// now we verify the authentication tag in 'constant time'
@@ -972,7 +972,7 @@ int aes_gcm_encrypt(unsigned char *output, //
972972

973973
gcm_setkey(&ctx, key, (const uint) key_len);
974974

975-
ret = gcm_crypt_and_tag(&ctx, ENCRYPT, iv, iv_len, aead, aead_len, input, output,
975+
ret = gcm_crypt_and_tag(&ctx, MG_ENCRYPT, iv, iv_len, aead, aead_len, input, output,
976976
input_length, tag, tag_len);
977977

978978
gcm_zero_ctx(&ctx);
@@ -992,7 +992,7 @@ int aes_gcm_decrypt(unsigned char *output, const unsigned char *input,
992992

993993
gcm_setkey(&ctx, key, (const uint) key_len);
994994

995-
ret = gcm_crypt_and_tag(&ctx, DECRYPT, iv, iv_len, NULL, 0, input, output,
995+
ret = gcm_crypt_and_tag(&ctx, MG_DECRYPT, iv, iv_len, NULL, 0, input, output,
996996
input_length, tag_buf, tag_len);
997997

998998
gcm_zero_ctx(&ctx);

src/tls_aes128.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#define AES_DECRYPTION 1 // whether AES decryption is supported
2828
/******************************************************************************/
2929

30-
#define ENCRYPT 1 // specify whether we're encrypting
31-
#define DECRYPT 0 // or decrypting
30+
#define MG_ENCRYPT 1 // specify whether we're encrypting
31+
#define MG_DECRYPT 0 // or decrypting
3232

3333
#include "arch.h"
3434

@@ -146,7 +146,7 @@ int gcm_setkey(gcm_context *ctx, // caller-provided context ptr
146146
******************************************************************************/
147147
int gcm_crypt_and_tag(
148148
gcm_context *ctx, // gcm context with key already setup
149-
int mode, // cipher direction: ENCRYPT (1) or DECRYPT (0)
149+
int mode, // cipher direction: MG_ENCRYPT (1) or MG_DECRYPT (0)
150150
const uchar *iv, // pointer to the 12-byte initialization vector
151151
size_t iv_len, // byte length if the IV. should always be 12
152152
const uchar *add, // pointer to the non-ciphered additional data
@@ -191,7 +191,7 @@ int gcm_auth_decrypt(
191191
******************************************************************************/
192192
int gcm_start(
193193
gcm_context *ctx, // pointer to user-provided GCM context
194-
int mode, // ENCRYPT (1) or DECRYPT (0)
194+
int mode, // MG_ENCRYPT (1) or MG_DECRYPT (0)
195195
const uchar *iv, // pointer to initialization vector
196196
size_t iv_len, // IV length in bytes (should == 12)
197197
const uchar *add, // pointer to additional AEAD data (NULL if none)

0 commit comments

Comments
 (0)