Skip to content

Commit 90bc6b8

Browse files
authored
Merge pull request #281 from AndrzejKurek/IOTCRYPT-968-zeroize-aes-variables
Zeroize local AES variables before exiting the function
2 parents 95b9f60 + 96ae5cd commit 90bc6b8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

library/aes.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,18 @@ int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
918918
PUT_UINT32_LE( X2, output, 8 );
919919
PUT_UINT32_LE( X3, output, 12 );
920920

921+
mbedtls_platform_zeroize( &X0, sizeof( X0 ) );
922+
mbedtls_platform_zeroize( &X1, sizeof( X1 ) );
923+
mbedtls_platform_zeroize( &X2, sizeof( X2 ) );
924+
mbedtls_platform_zeroize( &X3, sizeof( X3 ) );
925+
926+
mbedtls_platform_zeroize( &Y0, sizeof( Y0 ) );
927+
mbedtls_platform_zeroize( &Y1, sizeof( Y1 ) );
928+
mbedtls_platform_zeroize( &Y2, sizeof( Y2 ) );
929+
mbedtls_platform_zeroize( &Y3, sizeof( Y3 ) );
930+
931+
mbedtls_platform_zeroize( &RK, sizeof( RK ) );
932+
921933
return( 0 );
922934
}
923935
#endif /* !MBEDTLS_AES_ENCRYPT_ALT */
@@ -986,6 +998,18 @@ int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
986998
PUT_UINT32_LE( X2, output, 8 );
987999
PUT_UINT32_LE( X3, output, 12 );
9881000

1001+
mbedtls_platform_zeroize( &X0, sizeof( X0 ) );
1002+
mbedtls_platform_zeroize( &X1, sizeof( X1 ) );
1003+
mbedtls_platform_zeroize( &X2, sizeof( X2 ) );
1004+
mbedtls_platform_zeroize( &X3, sizeof( X3 ) );
1005+
1006+
mbedtls_platform_zeroize( &Y0, sizeof( Y0 ) );
1007+
mbedtls_platform_zeroize( &Y1, sizeof( Y1 ) );
1008+
mbedtls_platform_zeroize( &Y2, sizeof( Y2 ) );
1009+
mbedtls_platform_zeroize( &Y3, sizeof( Y3 ) );
1010+
1011+
mbedtls_platform_zeroize( &RK, sizeof( RK ) );
1012+
9891013
return( 0 );
9901014
}
9911015
#endif /* !MBEDTLS_AES_DECRYPT_ALT */

0 commit comments

Comments
 (0)