1/* 2 * Copyright (c) 2006-2007,2012,2014 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24 25/*! 26 @header vmdh 27 The functions provided in vmdh.h implement the crypto exchange required 28 for a Diffie-Hellman voicemail exchange. 29*/ 30 31#ifndef _SECURITY_VMDH_H_ 32#define _SECURITY_VMDH_H_ 33 34#include <stdint.h> 35#include <stdbool.h> 36#include <sys/types.h> 37 38#ifdef __cplusplus 39extern "C" { 40#endif 41 42typedef struct vmdh *vmdh_t; 43 44/* Return a newly allocated vmdh object given g, p and the recip of p recip. 45 The recip and recip_len parameters are constant for a given p. They are 46 optional although providing them improves performance. 47 The caller should call vmdh_destroy once the returned handle is no longer 48 needed. */ 49vmdh_t vmdh_create(uint32_t g, const uint8_t *p, size_t p_len, 50 const uint8_t *recip, size_t recip_len); 51 52/* Generate a dh private/public keypair and return the public key in pub_key. 53 on input *pub_key_len is the number of bytes available in pub_key, on output 54 pub_key_len is the number of bytes actually in pub_key. Returns true on 55 success and false on failure. */ 56bool vmdh_generate_key(vmdh_t vmdh, uint8_t *pub_key, size_t *pub_key_len); 57 58/* Given the length of a password return the size of the encrypted password. */ 59#define vmdh_encpw_len(PWLEN) (((PWLEN) & ~0xf) + 16) 60 61/* Given a vmdh handle and the other parties public key pub_key (of 62 pub_key_len bytes long), encrypt the password given by pw of pw_len bytes 63 long and return it in encpw. On input *enc_pw contains the number of bytes 64 available in encpw, on output *encpw will contain the actual length of 65 encpw. */ 66bool vmdh_encrypt_password(vmdh_t vmdh, 67 const uint8_t *pub_key, size_t pub_key_len, 68 const uint8_t *pw, size_t pw_len, uint8_t *encpw, size_t *encpw_len); 69 70/* Destroy a vmdh object created with vmdh_create(). */ 71void vmdh_destroy(vmdh_t vmdh); 72 73#ifdef __cplusplus 74} 75#endif 76 77#endif /* _SECURITY_VMDH_H_ */ 78