3 * Copyright (c) 2019 Apple Computer, Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * DNS SIG(0) signature generation for DNSSD SRP using Security Framework.
19 * Functions required for loading, saving, and generating public/private keypairs, extracting the public key
20 * into KEY RR data, and computing hashatures.
24 #include <arpa/inet.h>
33 #define SRP_CRYPTO_MACOS_INTERNAL
34 #include "srp-crypto.h"
36 // Function to generate a signature given some data and a private key
38 srp_hmac_iov(hmac_key_t
*key
, uint8_t *output
, size_t max
, struct iovec
*iov
, int count
)
40 // int digest_size = 0;
42 (void)count
;(void)iov
;(void)output
; (void)key
; (void)max
;
43 #define KABLOOIE line = __LINE__ - 1; goto kablooie
45 switch(key
->algorithm
) {
46 case SRP_HMAC_TYPE_SHA256
:
47 // digest_size = mbedtls_md_get_size(md_type);
50 ERROR("srp_hmac_iov: unsupported HMAC hash algorithm: %d", key
->algorithm
);
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
);
59 // if ((status = mbedtls_md_hmac_starts(&ctx, key->secret, key->length)) != 0) {
62 // for (i = 0; i < count; i++) {
63 // if ((status = mbedtls_md_hmac_update(&ctx, iov[i].iov_base, iov[i].iov_len)) != 0) {
67 // if ((status = mbedtls_md_hmac_finish(&ctx, output)) != 0) {
73 srp_base64_parse(char *src
, size_t *len_ret
, uint8_t *buf
, size_t buflen
)
75 (void)src
; (void)len_ret
; (void)buf
; (void)buflen
;
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
) {
81 } else if (ret
== MBEDTLS_ERR_BASE64_INVALID_CHARACTER
) {
95 // c-file-style: "bsd"
98 // indent-tabs-mode: nil