]>
git.saurik.com Git - apple/security.git/blob - sec/securityd/keystore.h
2 * Copyright (c) 2010 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 The functions provided in keystore.h provide an interface to
27 the AppleKeyStore kext.
30 #ifndef _SECURITYD_KEYSTORE_H_
31 #define _SECURITYD_KEYSTORE_H_
33 #include <IOKit/IOKitLib.h>
37 * ks objects are NOT C++ objects. Nevertheless, we can at least keep C++
38 * aware of type compatibility.
40 typedef struct ks_object_s
{
44 ks_object_s(const ks_object_s
&);
45 void operator=(const ks_object_s
&);
49 struct ks_object_s
*_kso
;
50 struct ks_key_s
*_ksk
;
51 struct ks_buffer_s
*_ksb
;
52 struct ks_stream_s
*_kss
;
53 } ks_object_t
__attribute__((transparent_union
));
57 #define KS_DECL(name) typedef struct name##_s : public ks_object_s {} *name##_t;
60 #define KS_DECL(name) typedef struct name##_s *name##_t;
67 #if defined(__cplusplus)
77 ks_key_t
ks_generate_key(long size
);
78 void ks_encrypt(ks_key_t key
, ks_object_t data_in
, ks_object_t data_out
);
79 void ks_decrypt(ks_key_t key
, ks_object_t data_in
, ks_object_t data_out
);
81 ks_buffer_t
ks_buffer(size_t capacity
);
82 size_t ks_get_length(ks_buffer_t buffer
);
83 void ks_set_length(ks_buffer_t buffer
, size_t length
);
84 uint8_t *ks_bytes(ks_buffer_t buffer
);
85 ks_buffer_t
ks_append(size_t capacity
);
88 /* TODO: Move to iokitutils or something since this is generic. */
89 io_connect_t
ks_connect_to_service(const char *className
);
91 io_connect_t
ks_get_connect(void);
95 @function ks_available
96 @abstract Check if the AppleKeyStore.kext is available, you must call
97 this function before using any other library function.
98 @result true, unless for some reason ks isn't available then false.
100 bool ks_available(void);
104 @abstract free something allocated by a ks_ function.
105 @param ks_object buffer allocated by the
107 void ks_free(ks_object_t ks_object
);
111 @abstract unwrap a key using the specified keyclass.
112 @param keybag the keybag handle containing the class key which will be
114 @param keyclass handle for the wrapping key.
115 @param bufferSize number of bytes available in array pointed to by buffer
116 @param buffer pointer to a buffer.
117 @param wrappedKeySize (output) size of the wrappedKey if it had been
119 @param error (optional) pointer to a CFErrorRef who's value will only be
120 changed if it is NULL, in which case the caller is responsible for
121 calling CFRelease on it.
122 @result Returns pointer to the wrappedKey, or
123 NULL if an error occured. Pass in a pointer to a CFErrorRef who's value
124 is NULL to obtain an error object.
125 @discussion If and only if NULL is passed for the buffer parameter, this
126 function will allocate a buffer to which it writes the wrappedKey.
128 uint8_t *ks_unwrap(uint64_t keybag
, uint64_t keyclass
,
129 const uint8_t *wrappedKey
, size_t wrappedKeySize
,
130 uint8_t *buffer
, size_t bufferSize
, size_t *keySize
);
134 @abstract wrap a 128 bit (16 byte), 192 bit (24 byte) or 256 bit (32 byte)
135 key using the specified keyclass.
136 @param keybag the keybag handle containing the class key which will be
138 @param keyclass handle for the wrapping key.
139 @param bufferSize number of bytes available in array pointed to by buffer
140 @param buffer pointer to a buffer.
141 @param wrappedKeySize (output) size of the wrappedKey if it had been
143 @param error (optional) pointer to a CFErrorRef who's value will only be
144 changed if it is NULL, in which case the caller is responsible for
145 calling CFRelease on it.
146 @result Returns pointer to the wrappedKey, or
147 NULL if an error occured. Pass in a pointer to a CFErrorRef who's value
148 is NULL to obtain an error object.
149 @discussion If and only if NULL is passed for the buffer parameter, this
150 function will allocate a buffer to which it writes the wrappedKey.
152 uint8_t *ks_wrap(uint64_t keybag
, uint64_t keyclass
,
153 const uint8_t *key
, size_t keyByteSize
,
154 uint8_t *buffer
, size_t bufferSize
, size_t *wrappedKeySize
);
156 #if defined(__cplusplus)
160 #endif /* _SECURITYD_KEYSTORE_H_ */