Clean TLS code

This commit is contained in:
Zhi Guan
2026-06-13 23:52:29 +08:00
parent a73c303339
commit 5d12858d41
8 changed files with 231 additions and 308 deletions

View File

@@ -115,72 +115,6 @@ int test_ghash(void)
return 1;
}
#if 0
int test_gcm(void)
{
BLOCK_CIPHER_KEY block_key;
uint8_t key[16];
uint8_t iv[12];
uint8_t aad[64];
uint8_t in[100];
uint8_t out[sizeof(in)];
uint8_t buf[sizeof(in)];
uint8_t tag[16];
rand_bytes(key, sizeof(key));
rand_bytes(iv, sizeof(iv));
rand_bytes(aad, sizeof(aad));
rand_bytes(in, sizeof(in));
#ifdef ENABLE_AES
memset(out, 0, sizeof(out));
memset(buf, 0, sizeof(buf));
memset(tag, 0, sizeof(tag));
if (block_cipher_set_encrypt_key(&block_key, BLOCK_CIPHER_aes128(), key) != 1) {
error_print();
return -1;
}
if (gcm_encrypt(&block_key, iv, sizeof(iv), aad, sizeof(aad), in, sizeof(in), out, sizeof(tag), tag) != 1) {
error_print();
return -1;
}
if (gcm_decrypt(&block_key, iv, sizeof(iv), aad, sizeof(aad), out, sizeof(out), tag, sizeof(tag), buf) != 1) {
error_print();
return -1;
}
if (memcmp(buf, in, sizeof(in)) != 0) {
error_print();
return -1;
}
#endif // ENABLE_AES
memset(out, 0, sizeof(out));
memset(buf, 0, sizeof(buf));
memset(tag, 0, sizeof(tag));
if (block_cipher_set_encrypt_key(&block_key, BLOCK_CIPHER_sm4(), key) != 1) {
error_print();
return -1;
}
if (gcm_encrypt(&block_key, iv, sizeof(iv), aad, sizeof(aad), in, sizeof(in), out, sizeof(tag), tag) != 1) {
error_print();
return -1;
}
if (gcm_decrypt(&block_key, iv, sizeof(iv), aad, sizeof(aad), out, sizeof(out), tag, sizeof(tag), buf) != 1) {
error_print();
return -1;
}
if (memcmp(buf, in, sizeof(in)) != 0) {
error_print();
return -1;
}
printf("%s() ok\n", __FUNCTION__);
return 1;
}
#endif
static int speed_ghash(void)
{
GHASH_CTX ghash_ctx;