]> git.saurik.com Git - apple/mdnsresponder.git/blob - ServiceRegistration/hmac-macos.c
mDNSResponder-1310.40.42.tar.gz
[apple/mdnsresponder.git] / ServiceRegistration / hmac-macos.c
1 /* hash.c
2 *
3 * Copyright (c) 2019 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * DNS SIG(0) signature generation for DNSSD SRP using Security Framework.
18 *
19 * Functions required for loading, saving, and generating public/private keypairs, extracting the public key
20 * into KEY RR data, and computing hashatures.
21 */
22
23 #include <stdio.h>
24 #include <arpa/inet.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29 #include <errno.h>
30
31 #include "srp.h"
32 #include "dns-msg.h"
33 #define SRP_CRYPTO_MACOS_INTERNAL
34 #include "srp-crypto.h"
35
36 // Function to generate a signature given some data and a private key
37 void
38 srp_hmac_iov(hmac_key_t *key, uint8_t *output, size_t max, struct iovec *iov, int count)
39 {
40 // int digest_size = 0;
41 // int i, line;
42 (void)count;(void)iov;(void)output; (void)key; (void)max;
43 #define KABLOOIE line = __LINE__ - 1; goto kablooie
44 #if 0
45 switch(key->algorithm) {
46 case SRP_HMAC_TYPE_SHA256:
47 // digest_size = mbedtls_md_get_size(md_type);
48 // break;
49 default:
50 ERROR("srp_hmac_iov: unsupported HMAC hash algorithm: %d", key->algorithm);
51 return;
52 }
53 if (max < digest_size) {
54 ERROR("srp_hmac_iov: not enough space in output buffer (%lu) for hash (%d).",
55 (unsigned long)max, digest_size);
56 return;
57 }
58 #endif
59 // if ((status = mbedtls_md_hmac_starts(&ctx, key->secret, key->length)) != 0) {
60 // KABLOOIE;
61 // }
62 // for (i = 0; i < count; i++) {
63 // if ((status = mbedtls_md_hmac_update(&ctx, iov[i].iov_base, iov[i].iov_len)) != 0) {
64 // KABLOOIE;
65 // }
66 // }
67 // if ((status = mbedtls_md_hmac_finish(&ctx, output)) != 0) {
68 // KABLOOIE;
69 // }
70 }
71
72 int
73 srp_base64_parse(char *src, size_t *len_ret, uint8_t *buf, size_t buflen)
74 {
75 (void)src; (void)len_ret; (void)buf; (void)buflen;
76 #if 0
77 size_t slen = strlen(src);
78 int ret = mbedtls_base64_decode(buf, buflen, len_ret, (const unsigned char *)src, slen);
79 if (ret == MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL) {
80 return ENOBUFS;
81 } else if (ret == MBEDTLS_ERR_BASE64_INVALID_CHARACTER) {
82 return EILSEQ;
83 } else if (ret < 0) {
84 return EINVAL;
85 }
86 return 0;
87 #else
88 return EINVAL;
89 #endif
90 }
91
92 // Local Variables:
93 // mode: C
94 // tab-width: 4
95 // c-file-style: "bsd"
96 // c-basic-offset: 4
97 // fill-column: 108
98 // indent-tabs-mode: nil
99 // End: