Changed AesGcmEncrypt and Decrypt to allow the same pointer to write and read buffers.
This commit is contained in:
parent
918ea3a074
commit
737cd127e8
@ -1551,6 +1551,7 @@ void AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
byte* c = out;
|
byte* c = out;
|
||||||
byte h[AES_BLOCK_SIZE];
|
byte h[AES_BLOCK_SIZE];
|
||||||
byte ctr[AES_BLOCK_SIZE];
|
byte ctr[AES_BLOCK_SIZE];
|
||||||
|
byte scratch[AES_BLOCK_SIZE];
|
||||||
|
|
||||||
CYASSL_ENTER("AesGcmEncrypt");
|
CYASSL_ENTER("AesGcmEncrypt");
|
||||||
|
|
||||||
@ -1565,19 +1566,18 @@ void AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
|
|
||||||
while (blocks--) {
|
while (blocks--) {
|
||||||
IncrementGcmCounter(ctr);
|
IncrementGcmCounter(ctr);
|
||||||
AesEncrypt(aes, ctr, c);
|
AesEncrypt(aes, ctr, scratch);
|
||||||
xorbuf(c, p, AES_BLOCK_SIZE);
|
xorbuf(scratch, p, AES_BLOCK_SIZE);
|
||||||
|
XMEMCPY(c, scratch, AES_BLOCK_SIZE);
|
||||||
|
|
||||||
p += AES_BLOCK_SIZE;
|
p += AES_BLOCK_SIZE;
|
||||||
c += AES_BLOCK_SIZE;
|
c += AES_BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
if (partial != 0) {
|
if (partial != 0) {
|
||||||
byte cPartial[AES_BLOCK_SIZE];
|
|
||||||
|
|
||||||
IncrementGcmCounter(ctr);
|
IncrementGcmCounter(ctr);
|
||||||
AesEncrypt(aes, ctr, cPartial);
|
AesEncrypt(aes, ctr, scratch);
|
||||||
XMEMCPY(c, cPartial, partial);
|
xorbuf(scratch, p, partial);
|
||||||
xorbuf(c, p, partial);
|
XMEMCPY(c, scratch, partial);
|
||||||
}
|
}
|
||||||
GHASH(h, authIn, authInSz, out, sz, authTag, authTagSz);
|
GHASH(h, authIn, authInSz, out, sz, authTag, authTagSz);
|
||||||
InitGcmCounter(ctr);
|
InitGcmCounter(ctr);
|
||||||
@ -1596,6 +1596,7 @@ int AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
byte* p = out;
|
byte* p = out;
|
||||||
byte h[AES_BLOCK_SIZE];
|
byte h[AES_BLOCK_SIZE];
|
||||||
byte ctr[AES_BLOCK_SIZE];
|
byte ctr[AES_BLOCK_SIZE];
|
||||||
|
byte scratch[AES_BLOCK_SIZE];
|
||||||
|
|
||||||
CYASSL_ENTER("AesGcmDecrypt");
|
CYASSL_ENTER("AesGcmDecrypt");
|
||||||
|
|
||||||
@ -1624,8 +1625,9 @@ int AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
|
|
||||||
while (blocks--) {
|
while (blocks--) {
|
||||||
IncrementGcmCounter(ctr);
|
IncrementGcmCounter(ctr);
|
||||||
AesEncrypt(aes, ctr, p);
|
AesEncrypt(aes, ctr, scratch);
|
||||||
xorbuf(p, c, AES_BLOCK_SIZE);
|
xorbuf(scratch, c, AES_BLOCK_SIZE);
|
||||||
|
XMEMCPY(p, scratch, AES_BLOCK_SIZE);
|
||||||
|
|
||||||
p += AES_BLOCK_SIZE;
|
p += AES_BLOCK_SIZE;
|
||||||
c += AES_BLOCK_SIZE;
|
c += AES_BLOCK_SIZE;
|
||||||
@ -1634,9 +1636,9 @@ int AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
byte pPartial[AES_BLOCK_SIZE];
|
byte pPartial[AES_BLOCK_SIZE];
|
||||||
|
|
||||||
IncrementGcmCounter(ctr);
|
IncrementGcmCounter(ctr);
|
||||||
AesEncrypt(aes, ctr, pPartial);
|
AesEncrypt(aes, ctr, scratch);
|
||||||
XMEMCPY(p, pPartial, partial);
|
xorbuf(scratch, c, partial);
|
||||||
xorbuf(p, c, partial);
|
XMEMCPY(p, scratch, partial);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user