Rewrite TLS 1.2 as a state machine

This commit is contained in:
Zhi Guan
2026-02-01 20:38:13 +08:00
parent a15e0f34c7
commit 9c58806408
27 changed files with 12984 additions and 1589 deletions

View File

@@ -8,5 +8,54 @@
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gmssl/mem.h>
#include <gmssl/error.h>
#include <gmssl/secp256r1_key.h>
int secp256r1_do_ecdh(const SECP256R1_KEY *key, const SECP256R1_KEY *peer_key, uint8_t out[32])
{
SECP256R1_POINT point;
secp256r1_t x;
secp256r1_t y;
if (!key || !peer_key || !out) {
error_print();
return -1;
}
secp256r1_point_mul(&point, key->private_key, &peer_key->public_key);
secp256r1_point_get_xy(&point, x, y);
secp256r1_to_32bytes(x, out);
gmssl_secure_clear(&point, sizeof(SECP256R1_POINT));
gmssl_secure_clear(x, sizeof(secp256r1_t));
gmssl_secure_clear(y, sizeof(secp256r1_t));
return 1;
}
int secp256r1_ecdh(const SECP256R1_KEY *key, const uint8_t uncompressed_point[65], uint8_t out[32])
{
SECP256R1_POINT point;
secp256r1_t x;
secp256r1_t y;
if (!key || !uncompressed_point || !out) {
error_print();
return -1;
}
if (secp256r1_point_from_uncompressed_octets(&point, uncompressed_point) != 1) {
error_print();
return -1;
}
secp256r1_point_mul(&point, key->private_key, &point);
secp256r1_point_get_xy(&point, x,y);
secp256r1_to_32bytes(x, out);
gmssl_secure_clear(&point, sizeof(SECP256R1_POINT));
gmssl_secure_clear(x, sizeof(secp256r1_t));
gmssl_secure_clear(y, sizeof(secp256r1_t));
return 1;
}