1 #define _POSIX_C_SOURCE 200809L
8 #define htonll(x) ((1==htonl(1)) ? (x) : ((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
12 #define ntohll(x) ((1==ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
15 unsigned int tls_hmac_message(unsigned char local,
16 struct TLSContext *context,
17 const unsigned char *buf,
19 const unsigned char *buf2,
20 int buf_len2, unsigned char *out,
26 int mac_size = outlen;
28 if (mac_size == TLS_SHA1_MAC_SIZE) {
29 hash_idx = find_hash("sha1");
30 } else if (mac_size == TLS_SHA384_MAC_SIZE) {
31 hash_idx = find_hash("sha384");
33 hash_idx = find_hash("sha256");
36 if (hmac_init(&hash, hash_idx,
37 local ? context->crypto.ctx_local_mac.local_mac : context->
38 crypto.ctx_remote_mac.remote_mac, mac_size)) {
44 sn = htonll(context->local_sequence_number);
46 sn = htonll(context->remote_sequence_number);
49 if (hmac_process(&hash, (unsigned char *)&sn, sizeof sn)) {
53 if (hmac_process(&hash, buf, buf_len)) {
57 if (buf2 && buf_len2) {
58 if (hmac_process(&hash, buf2, buf_len2)) {
62 unsigned long ref_outlen = outlen;
63 if (hmac_done(&hash, out, &ref_outlen)) {
67 return (unsigned int)ref_outlen;