1183234Ssimon/*
2280304Sjkim * Copyright (c) 2007 KISA(Korea Information Security Agency). All rights reserved.
3183234Ssimon *
4183234Ssimon * Redistribution and use in source and binary forms, with or without
5183234Ssimon * modification, are permitted provided that the following conditions
6183234Ssimon * are met:
7183234Ssimon * 1. Redistributions of source code must retain the above copyright
8183234Ssimon *    notice, this list of conditions and the following disclaimer.
9183234Ssimon * 2. Neither the name of author nor the names of its contributors may
10183234Ssimon *    be used to endorse or promote products derived from this software
11183234Ssimon *    without specific prior written permission.
12183234Ssimon *
13183234Ssimon * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14183234Ssimon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15183234Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16183234Ssimon * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17183234Ssimon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18183234Ssimon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19183234Ssimon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20183234Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21183234Ssimon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22183234Ssimon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23183234Ssimon * SUCH DAMAGE.
24183234Ssimon *
25183234Ssimon */
26183234Ssimon/* ====================================================================
27183234Ssimon * Copyright (c) 1998-2007 The OpenSSL Project.  All rights reserved.
28183234Ssimon *
29183234Ssimon * Redistribution and use in source and binary forms, with or without
30183234Ssimon * modification, are permitted provided that the following conditions
31183234Ssimon * are met:
32183234Ssimon *
33183234Ssimon * 1. Redistributions of source code must retain the above copyright
34280304Sjkim *    notice, this list of conditions and the following disclaimer.
35183234Ssimon *
36183234Ssimon * 2. Redistributions in binary form must reproduce the above copyright
37183234Ssimon *    notice, this list of conditions and the following disclaimer in
38183234Ssimon *    the documentation and/or other materials provided with the
39183234Ssimon *    distribution.
40183234Ssimon *
41183234Ssimon * 3. All advertising materials mentioning features or use of this
42183234Ssimon *    software must display the following acknowledgment:
43183234Ssimon *    "This product includes software developed by the OpenSSL Project
44183234Ssimon *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
45183234Ssimon *
46183234Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
47183234Ssimon *    endorse or promote products derived from this software without
48183234Ssimon *    prior written permission. For written permission, please contact
49183234Ssimon *    openssl-core@openssl.org.
50183234Ssimon *
51183234Ssimon * 5. Products derived from this software may not be called "OpenSSL"
52183234Ssimon *    nor may "OpenSSL" appear in their names without prior written
53183234Ssimon *    permission of the OpenSSL Project.
54183234Ssimon *
55183234Ssimon * 6. Redistributions of any form whatsoever must retain the following
56183234Ssimon *    acknowledgment:
57183234Ssimon *    "This product includes software developed by the OpenSSL Project
58183234Ssimon *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
59183234Ssimon *
60183234Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
61183234Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62183234Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
63183234Ssimon * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
64183234Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
65183234Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
66183234Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
67183234Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68183234Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
69183234Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
70183234Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
71183234Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE.
72183234Ssimon * ====================================================================
73183234Ssimon *
74183234Ssimon * This product includes cryptographic software written by Eric Young
75183234Ssimon * (eay@cryptsoft.com).  This product includes software written by Tim
76183234Ssimon * Hudson (tjh@cryptsoft.com).
77183234Ssimon *
78183234Ssimon */
79183234Ssimon
80183234Ssimon#ifndef HEADER_SEED_H
81280304Sjkim# define HEADER_SEED_H
82183234Ssimon
83280304Sjkim# include <openssl/opensslconf.h>
84280304Sjkim# include <openssl/e_os2.h>
85280304Sjkim# include <openssl/crypto.h>
86183234Ssimon
87280304Sjkim# ifdef OPENSSL_NO_SEED
88280304Sjkim#  error SEED is disabled.
89280304Sjkim# endif
90183234Ssimon
91280304Sjkim/* look whether we need 'long' to get 32 bits */
92280304Sjkim# ifdef AES_LONG
93280304Sjkim#  ifndef SEED_LONG
94280304Sjkim#   define SEED_LONG 1
95280304Sjkim#  endif
96183234Ssimon# endif
97183234Ssimon
98280304Sjkim# if !defined(NO_SYS_TYPES_H)
99280304Sjkim#  include <sys/types.h>
100280304Sjkim# endif
101183234Ssimon
102280304Sjkim# define SEED_BLOCK_SIZE 16
103280304Sjkim# define SEED_KEY_LENGTH 16
104183234Ssimon
105183234Ssimon
106183234Ssimon#ifdef  __cplusplus
107183234Ssimonextern "C" {
108183234Ssimon#endif
109183234Ssimon
110183234Ssimontypedef struct seed_key_st {
111280304Sjkim# ifdef SEED_LONG
112183234Ssimon    unsigned long data[32];
113280304Sjkim# else
114183234Ssimon    unsigned int data[32];
115280304Sjkim# endif
116183234Ssimon} SEED_KEY_SCHEDULE;
117183234Ssimon
118280304Sjkim# ifdef OPENSSL_FIPS
119280304Sjkimvoid private_SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH],
120280304Sjkim                          SEED_KEY_SCHEDULE *ks);
121280304Sjkim# endif
122280304Sjkimvoid SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH],
123280304Sjkim                  SEED_KEY_SCHEDULE *ks);
124183234Ssimon
125280304Sjkimvoid SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE],
126280304Sjkim                  unsigned char d[SEED_BLOCK_SIZE],
127280304Sjkim                  const SEED_KEY_SCHEDULE *ks);
128280304Sjkimvoid SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE],
129280304Sjkim                  unsigned char d[SEED_BLOCK_SIZE],
130280304Sjkim                  const SEED_KEY_SCHEDULE *ks);
131183234Ssimon
132280304Sjkimvoid SEED_ecb_encrypt(const unsigned char *in, unsigned char *out,
133280304Sjkim                      const SEED_KEY_SCHEDULE *ks, int enc);
134280304Sjkimvoid SEED_cbc_encrypt(const unsigned char *in, unsigned char *out, size_t len,
135280304Sjkim                      const SEED_KEY_SCHEDULE *ks,
136280304Sjkim                      unsigned char ivec[SEED_BLOCK_SIZE], int enc);
137183234Ssimonvoid SEED_cfb128_encrypt(const unsigned char *in, unsigned char *out,
138280304Sjkim                         size_t len, const SEED_KEY_SCHEDULE *ks,
139280304Sjkim                         unsigned char ivec[SEED_BLOCK_SIZE], int *num,
140280304Sjkim                         int enc);
141183234Ssimonvoid SEED_ofb128_encrypt(const unsigned char *in, unsigned char *out,
142280304Sjkim                         size_t len, const SEED_KEY_SCHEDULE *ks,
143280304Sjkim                         unsigned char ivec[SEED_BLOCK_SIZE], int *num);
144183234Ssimon
145183234Ssimon#ifdef  __cplusplus
146183234Ssimon}
147183234Ssimon#endif
148183234Ssimon
149280304Sjkim#endif                          /* HEADER_SEED_H */
150