]> git.saurik.com Git - apple/security.git/blob - sec/Security/vmdh.h
Security-55163.44.tar.gz
[apple/security.git] / sec / Security / vmdh.h
1 /*
2 * vmdh.h
3 * Security
4 *
5 * Created by Michael Brouwer on 11/7/06.
6 * Copyright (c) 2006-2007 Apple Inc. All Rights Reserved.
7 *
8 */
9
10 /*!
11 @header vmdh
12 The functions provided in vmdh.h implement the crypto exchange required
13 for a Diffie-Hellman voicemail exchange.
14 */
15
16 #ifndef _SECURITY_VMDH_H_
17 #define _SECURITY_VMDH_H_
18
19 #include <stdint.h>
20 #include <stdbool.h>
21 #include <sys/types.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 typedef struct vmdh *vmdh_t;
28
29 /* Return a newly allocated vmdh object given g, p and the recip of p recip.
30 The recip and recip_len parameters are constant for a given p. They are
31 optional although providing them improves performance.
32 The caller should call vmdh_destroy once the returned handle is no longer
33 needed. */
34 vmdh_t vmdh_create(uint32_t g, const uint8_t *p, size_t p_len,
35 const uint8_t *recip, size_t recip_len);
36
37 /* Generate a dh private/public keypair and return the public key in pub_key.
38 on input *pub_key_len is the number of bytes available in pub_key, on output
39 pub_key_len is the number of bytes actually in pub_key. Returns true on
40 success and false on failure. */
41 bool vmdh_generate_key(vmdh_t vmdh, uint8_t *pub_key, size_t *pub_key_len);
42
43 /* Given the length of a password return the size of the encrypted password. */
44 #define vmdh_encpw_len(PWLEN) (((PWLEN) & ~0xf) + 16)
45
46 /* Given a vmdh handle and the other parties public key pub_key (of
47 pub_key_len bytes long), encrypt the password given by pw of pw_len bytes
48 long and return it in encpw. On input *enc_pw contains the number of bytes
49 available in encpw, on output *encpw will contain the actual length of
50 encpw. */
51 bool vmdh_encrypt_password(vmdh_t vmdh,
52 const uint8_t *pub_key, size_t pub_key_len,
53 const uint8_t *pw, size_t pw_len, uint8_t *encpw, size_t *encpw_len);
54
55 /* Destroy a vmdh object created with vmdh_create(). */
56 void vmdh_destroy(vmdh_t vmdh);
57
58 #ifdef __cplusplus
59 }
60 #endif
61
62 #endif /* _SECURITY_VMDH_H_ */