1 | /* $NetBSD: nist_ctr_aes_rijndael.h,v 1.1 2011/11/19 22:51:22 tls Exp $ */ |
2 | |
3 | /*- |
4 | * Copyright (c) 2011 The NetBSD Foundation, Inc. |
5 | * All rights reserved. |
6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Thor Lancelot Simon. |
9 | * |
10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions |
12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. |
18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ |
31 | |
32 | /* |
33 | * Copyright (c) 2007 Henric Jungheim <software@henric.info> |
34 | * |
35 | * Permission to use, copy, modify, and distribute this software for any |
36 | * purpose with or without fee is hereby granted, provided that the above |
37 | * copyright notice and this permission notice appear in all copies. |
38 | * |
39 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
40 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
41 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
42 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
43 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
44 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
45 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
46 | */ |
47 | |
48 | /* |
49 | * Interface adapter for Rijndael implmentation (for use by NIST SP 800-90 CTR_DRBG) |
50 | */ |
51 | |
52 | #ifndef NIST_AES_RIJNDAEL_H |
53 | #define NIST_AES_RIJNDAEL_H |
54 | |
55 | #include <crypto/rijndael/rijndael.h> |
56 | |
57 | #define NIST_AES_MAXKEYBITS 256 |
58 | #define NIST_AES_MAXKEYBYTES (NIST_AES_MAXKEYBITS / 8) |
59 | #define NIST_AES_MAXKEYINTS (NIST_AES_MAXKEYBYTES / sizeof(int)) |
60 | |
61 | #define NIST_AES_BLOCKSIZEBITS 128 |
62 | #define NIST_AES_BLOCKSIZEBYTES (NIST_AES_BLOCKSIZEBITS / 8) |
63 | #define NIST_AES_BLOCKSIZEINTS (NIST_AES_BLOCKSIZEBYTES / sizeof(int)) |
64 | |
65 | typedef rijndael_ctx NIST_AES_ENCRYPT_CTX; |
66 | |
67 | static inline void |
68 | NIST_AES_ECB_Encrypt(const NIST_AES_ENCRYPT_CTX *ctx, |
69 | const void *src, void* dst) |
70 | { |
71 | rijndael_encrypt(ctx, src, dst); |
72 | } |
73 | |
74 | static inline int |
75 | NIST_AES_Schedule_Encryption(NIST_AES_ENCRYPT_CTX *ctx, |
76 | const void *key, int bits) |
77 | { |
78 | rijndael_set_key(ctx, key, bits); |
79 | return 0; |
80 | } |
81 | |
82 | #endif /* NIST_AES_RIJNDAEL_H */ |
83 | |