2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
27 B_ALGORITHM_METHOD
*chooser
[] = {
33 void dumpItem(ITEM
&item
, const char *name
);
35 unsigned char seed
[] = { 17, 205, 99, 13, 6, 199 };
36 char data
[] = "These are the times that try men's souls.";
40 if (status = (expr)) { printf("error %d at %d\n", status, __LINE__); abort(); } else /* ok */
42 int main(int argc
, char *argv
[])
47 key
.data
= (unsigned char *)"Walla Walla Washington! Yeah, yeah, yeah!";
48 key
.len
= strlen((const char *)key
.data
);
49 B_KEY_OBJ bsKey
= NULL
;
50 check(B_CreateKeyObject(&bsKey
));
51 check(B_SetKeyInfo(bsKey
, KI_Item
, POINTER(&key
)));
53 B_ALGORITHM_OBJ macAlg
= NULL
;
54 check(B_CreateAlgorithmObject(&macAlg
));
55 B_DIGEST_SPECIFIER macSpec
;
56 macSpec
.digestInfoType
= AI_SHA1
;
57 macSpec
.digestInfoParams
= NULL_PTR
;
58 check(B_SetAlgorithmInfo(macAlg
, AI_HMAC
, POINTER(&macSpec
)));
60 check(B_DigestInit(macAlg
, bsKey
, chooser
, NULL
));
61 check(B_DigestUpdate(macAlg
,
62 POINTER(data
), sizeof(data
), NULL
));
65 check(B_DigestFinal(macAlg
, POINTER(mac
), &length
, sizeof(mac
),
67 ITEM macItem
; macItem
.data
= POINTER(mac
); macItem
.len
= length
;
68 dumpItem(macItem
, "MAC");
70 check(B_DigestUpdate(macAlg
, POINTER(data
), 10, NULL
));
71 check(B_DigestUpdate(macAlg
,
72 POINTER(data
+10), sizeof(data
)-10, NULL
));
73 check(B_DigestFinal(macAlg
, POINTER(mac
), &length
, sizeof(mac
),
75 macItem
.data
= POINTER(mac
); macItem
.len
= length
;
76 dumpItem(macItem
, "MAC");
83 void dumpItem(ITEM
&item
, const char *name
)
85 printf("%s [%d] ", name
, item
.len
);
86 for (unsigned char *p
= item
.data
; p
< item
.data
+ item
.len
; p
++)
95 void T_free(POINTER p
)
98 POINTER
T_malloc(unsigned int size
)
99 { return (POINTER
)malloc(size
); }
101 POINTER
T_realloc(POINTER p
, unsigned int size
)
102 { return (POINTER
)realloc(p
, size
); }
104 int T_memcmp(POINTER p1
, POINTER p2
, unsigned int size
)
105 { return memcmp(p1
, p2
, size
); }
106 void T_memcpy(POINTER p1
, POINTER p2
, unsigned int size
)
107 { memcpy(p1
, p2
, size
); }
108 void T_memmove(POINTER p1
, POINTER p2
, unsigned int size
)
109 { memmove(p1
, p2
, size
); }
110 void T_memset(POINTER p1
, int size
, unsigned int val
)
111 { memset(p1
, size
, val
); }
112 extern "C" int T_GetDynamicList()
113 { printf("GetDynamicList!\n"); abort(); }