1 #define _POSIX_C_SOURCE 200809L
5 void tls_destroy_hash(struct TLSContext *context) {
7 context->hs_index = -1;
12 static void create_hash(struct TLSContext *context) {
19 int hash_size = tls_mac_length(context);
21 if (hash_size == TLS_SHA384_MAC_SIZE) {
22 index = find_hash("sha384");
24 index = find_hash("sha256");
26 context->hs_index = index;
27 context->handshake_init = hash_descriptor[index].init;
28 context->handshake_process = hash_descriptor[index].process;
29 context->handshake_done = hash_descriptor[index].done;
31 context->handshake_init(&context->hs_hash);
32 context->hs_created = 1;
35 int tls_update_hash(struct TLSContext *context, const unsigned char *in,
45 if (!context->hs_created) {
49 context->handshake_process(&context->hs_hash, in, len);
51 if (context->request_client_certificate) {
52 tls_buffer_append(&context->cached_handshake, in, len);
57 int tls_done_hash(struct TLSContext *context, unsigned char *hout) {
62 if (!context->hs_created) {
67 context->handshake_done(&context->hs_hash, hout);
69 /* TODO zero memory? */
70 context->hs_created = 0;
72 tls_buffer_free(&context->cached_handshake);
73 return tls_mac_length(context);
76 int tls_get_hash_idx(struct TLSContext *context) {
81 switch (tls_mac_length(context)) {
82 case TLS_SHA256_MAC_SIZE:
83 return find_hash("sha256");
84 case TLS_SHA384_MAC_SIZE:
85 return find_hash("sha384");
86 case TLS_SHA1_MAC_SIZE:
87 return find_hash("sha1");
92 int tls_get_hash(struct TLSContext *context, unsigned char *hout) {
99 if (!context->hs_created) {
103 prec = context->hs_hash;
105 context->handshake_done(&prec, hout);
107 return tls_mac_length(context);