]> git.saurik.com Git - apple/security.git/blob - AppleCSP/AES/rijndaelApi.h
Security-29.tar.gz
[apple/security.git] / AppleCSP / AES / rijndaelApi.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 /*
20 * rijndaelApi.h - AES API layer
21 *
22 * Based on rijndael-api-ref.h v2.0 written by Paulo Barreto
23 * and Vincent Rijmen
24 */
25
26 #ifndef _RIJNDAEL_API_REF_H_
27 #define _RIJNDAEL_API_REF_H_
28
29 #include <stdio.h>
30 #include "rijndael-alg-ref.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /* Error Codes */
37 #define BAD_KEY_MAT -1 /* Key material not of correct
38 length */
39 #define BAD_KEY_INSTANCE -2 /* Key passed is not valid */
40
41 #define MAX_AES_KEY_SIZE (MAX_AES_KEY_BITS / 8)
42 #define MAX_AES_BLOCK_SIZE (MAX_AES_BLOCK_BITS / 8)
43 #define MAX_AES_IV_SIZE MAX_AES_BLOCK_SIZE
44
45 #define TRUE 1
46 #define FALSE 0
47
48 /* The structure for key information */
49 typedef struct {
50 word32 keyLen; /* Length of the key in bits */
51 word32 blockLen; /* Length of block in bits */
52 word32 columns; /* optimization, blockLen / 32 */
53 word8 keySched[MAXROUNDS+1][4][MAXBC];
54 } keyInstance;
55
56 int makeKey(
57 keyInstance *key,
58 int keyLen, // in BITS
59 int blockLen, // in BITS
60 word8 *keyMaterial,
61 int enable128Opt);
62
63 /*
64 * Simplified single-block encrypt/decrypt.
65 */
66 int rijndaelBlockEncrypt(
67 keyInstance *key,
68 word8 *input,
69 word8 *outBuffer);
70 int rijndaelBlockDecrypt(
71 keyInstance *key,
72 word8 *input,
73 word8 *outBuffer);
74
75 /*
76 * Optimized routines for 128 bit block and 128 bit key.
77 */
78 int rijndaelBlockEncrypt128(
79 keyInstance *key,
80 word8 *input,
81 word8 *outBuffer);
82 int rijndaelBlockDecrypt128(
83 keyInstance *key,
84 word8 *input,
85 word8 *outBuffer);
86
87 #ifdef __ppc__
88 /*
89 * dmitch addenda 4/11/2001: 128-bit only vectorized encrypt/decrypt with no CBC
90 */
91 void vBlockEncrypt128(
92 keyInstance *key,
93 word8 *input,
94 word8 *outBuffer);
95 void vBlockDecrypt128(
96 keyInstance *key,
97 word8 *input,
98 word8 *outBuffer);
99 #endif __ppc__
100
101 /* temp switch for runtime enable/disable */
102 extern int doAES128;
103
104 /* ptr to one of several (possibly optimized) encrypt/decrypt functions */
105 typedef int (*aesCryptFcn)(
106 keyInstance *key,
107 word8 *input,
108 word8 *outBuffer);
109
110 #ifdef __cplusplus
111 }
112 #endif // cplusplus
113
114 #endif // RIJNDAEL_API_REF
115
116