1 /**
2 * @file dtls.c DTLS functions
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6
7 #include <re.h>
8 #include <baresip.h>
9 #include "dtls_srtp.h"
10
11
dtls_print_sha1_fingerprint(struct re_printf * pf,const struct tls * tls)12 int dtls_print_sha1_fingerprint(struct re_printf *pf, const struct tls *tls)
13 {
14 uint8_t md[20];
15 unsigned int i;
16 int err = 0;
17
18 if (!tls)
19 return EINVAL;
20
21 err = tls_fingerprint(tls, TLS_FINGERPRINT_SHA1, md, sizeof(md));
22 if (err)
23 return err;
24
25 for (i=0; i<sizeof(md); i++) {
26 err |= re_hprintf(pf, "%s%02X", i==0 ? "" : ":", md[i]);
27 }
28
29 return err;
30 }
31
32
dtls_print_sha256_fingerprint(struct re_printf * pf,const struct tls * tls)33 int dtls_print_sha256_fingerprint(struct re_printf *pf, const struct tls *tls)
34 {
35 uint8_t md[32];
36 unsigned int i;
37 int err = 0;
38
39 if (!tls)
40 return EINVAL;
41
42 err = tls_fingerprint(tls, TLS_FINGERPRINT_SHA256, md, sizeof(md));
43 if (err)
44 return err;
45
46 for (i=0; i<sizeof(md); i++) {
47 err |= re_hprintf(pf, "%s%02X", i==0 ? "" : ":", md[i]);
48 }
49
50 return err;
51 }
52