]> git.saurik.com Git - apple/security.git/blame - OSX/libsecurity_apple_csp/lib/rijndaelApi.h
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_apple_csp / lib / rijndaelApi.h
CommitLineData
b1ab9ed8 1/*
d8f41ccd 2 * Copyright (c) 2000-2001,2011,2014 Apple Inc. All Rights Reserved.
b1ab9ed8
A
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
33extern "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 */
49typedef 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
56int 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 */
66int rijndaelBlockEncrypt(
67 keyInstance *key,
68 word8 *input,
69 word8 *outBuffer);
70int rijndaelBlockDecrypt(
71 keyInstance *key,
72 word8 *input,
73 word8 *outBuffer);
74
75#if !GLADMAN_AES_128_ENABLE
76/*
77 * Optimized routines for 128 bit block and 128 bit key.
78 */
79int rijndaelBlockEncrypt128(
80 keyInstance *key,
81 word8 *input,
82 word8 *outBuffer);
83int rijndaelBlockDecrypt128(
84 keyInstance *key,
85 word8 *input,
86 word8 *outBuffer);
87#endif /* !GLADMAN_AES_128_ENABLE */
88
89#if defined(__ppc__) && defined(ALTIVEC_ENABLE)
90/*
91 * dmitch addenda 4/11/2001: 128-bit only vectorized encrypt/decrypt with no CBC
92 */
93void vBlockEncrypt128(
94 keyInstance *key,
95 word8 *input,
96 word8 *outBuffer);
97void vBlockDecrypt128(
98 keyInstance *key,
99 word8 *input,
100 word8 *outBuffer);
101
102/* temp switch for runtime enable/disable */
103extern int doAES128;
104
105#endif /* __ppc__ && ALTIVEC_ENABLE */
106
107/* ptr to one of several (possibly optimized) encrypt/decrypt functions */
108typedef int (*aesCryptFcn)(
109 keyInstance *key,
110 word8 *input,
111 word8 *outBuffer);
112
113#ifdef __cplusplus
114}
115#endif // cplusplus
116
117#endif // RIJNDAEL_API_REF
118
119