camellia.h revision 194206
1162911Ssimon/* crypto/camellia/camellia.h -*- mode:C; c-file-style: "eay" -*- */ 2162911Ssimon/* ==================================================================== 3162911Ssimon * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 4162911Ssimon * 5162911Ssimon * Redistribution and use in source and binary forms, with or without 6162911Ssimon * modification, are permitted provided that the following conditions 7162911Ssimon * are met: 8162911Ssimon * 9162911Ssimon * 1. Redistributions of source code must retain the above copyright 10162911Ssimon * notice, this list of conditions and the following disclaimer. 11162911Ssimon * 12162911Ssimon * 2. Redistributions in binary form must reproduce the above copyright 13162911Ssimon * notice, this list of conditions and the following disclaimer in 14162911Ssimon * the documentation and/or other materials provided with the 15162911Ssimon * distribution. 16162911Ssimon * 17162911Ssimon * 3. All advertising materials mentioning features or use of this 18162911Ssimon * software must display the following acknowledgment: 19162911Ssimon * "This product includes software developed by the OpenSSL Project 20162911Ssimon * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 21162911Ssimon * 22162911Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 23162911Ssimon * endorse or promote products derived from this software without 24162911Ssimon * prior written permission. For written permission, please contact 25162911Ssimon * openssl-core@openssl.org. 26162911Ssimon * 27162911Ssimon * 5. Products derived from this software may not be called "OpenSSL" 28162911Ssimon * nor may "OpenSSL" appear in their names without prior written 29162911Ssimon * permission of the OpenSSL Project. 30162911Ssimon * 31162911Ssimon * 6. Redistributions of any form whatsoever must retain the following 32162911Ssimon * acknowledgment: 33162911Ssimon * "This product includes software developed by the OpenSSL Project 34162911Ssimon * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 35162911Ssimon * 36162911Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 37162911Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38162911Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39162911Ssimon * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40162911Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41162911Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 42162911Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 43162911Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44162911Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 45162911Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46162911Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 47162911Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE. 48162911Ssimon * ==================================================================== 49162911Ssimon * 50162911Ssimon */ 51162911Ssimon 52162911Ssimon#ifndef HEADER_CAMELLIA_H 53162911Ssimon#define HEADER_CAMELLIA_H 54162911Ssimon 55162911Ssimon#include <openssl/opensslconf.h> 56162911Ssimon 57162911Ssimon#ifdef OPENSSL_NO_CAMELLIA 58162911Ssimon#error CAMELLIA is disabled. 59162911Ssimon#endif 60162911Ssimon 61162911Ssimon#define CAMELLIA_ENCRYPT 1 62162911Ssimon#define CAMELLIA_DECRYPT 0 63162911Ssimon 64162911Ssimon/* Because array size can't be a const in C, the following two are macros. 65162911Ssimon Both sizes are in bytes. */ 66162911Ssimon 67162911Ssimon#ifdef __cplusplus 68162911Ssimonextern "C" { 69162911Ssimon#endif 70162911Ssimon 71162911Ssimon/* This should be a hidden type, but EVP requires that the size be known */ 72162911Ssimon 73162911Ssimon#define CAMELLIA_BLOCK_SIZE 16 74162911Ssimon#define CAMELLIA_TABLE_BYTE_LEN 272 75162911Ssimon#define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / 4) 76162911Ssimon 77162911Ssimon /* to match with WORD */ 78162911Ssimontypedef unsigned int KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN]; 79162911Ssimon 80162911Ssimonstruct camellia_key_st 81162911Ssimon { 82162911Ssimon KEY_TABLE_TYPE rd_key; 83162911Ssimon int bitLength; 84162911Ssimon void (*enc)(const unsigned int *subkey, unsigned int *io); 85162911Ssimon void (*dec)(const unsigned int *subkey, unsigned int *io); 86162911Ssimon }; 87162911Ssimon 88162911Ssimontypedef struct camellia_key_st CAMELLIA_KEY; 89162911Ssimon 90194206Ssimon#ifdef OPENSSL_FIPS 91194206Ssimonint private_Camellia_set_key(const unsigned char *userKey, const int bits, 92194206Ssimon CAMELLIA_KEY *key); 93194206Ssimon#endif 94194206Ssimon 95162911Ssimonint Camellia_set_key(const unsigned char *userKey, const int bits, 96162911Ssimon CAMELLIA_KEY *key); 97162911Ssimon 98162911Ssimonvoid Camellia_encrypt(const unsigned char *in, unsigned char *out, 99162911Ssimon const CAMELLIA_KEY *key); 100162911Ssimonvoid Camellia_decrypt(const unsigned char *in, unsigned char *out, 101162911Ssimon const CAMELLIA_KEY *key); 102162911Ssimon 103162911Ssimonvoid Camellia_ecb_encrypt(const unsigned char *in, unsigned char *out, 104162911Ssimon const CAMELLIA_KEY *key, const int enc); 105162911Ssimonvoid Camellia_cbc_encrypt(const unsigned char *in, unsigned char *out, 106162911Ssimon const unsigned long length, const CAMELLIA_KEY *key, 107162911Ssimon unsigned char *ivec, const int enc); 108162911Ssimonvoid Camellia_cfb128_encrypt(const unsigned char *in, unsigned char *out, 109162911Ssimon const unsigned long length, const CAMELLIA_KEY *key, 110162911Ssimon unsigned char *ivec, int *num, const int enc); 111162911Ssimonvoid Camellia_cfb1_encrypt(const unsigned char *in, unsigned char *out, 112162911Ssimon const unsigned long length, const CAMELLIA_KEY *key, 113162911Ssimon unsigned char *ivec, int *num, const int enc); 114162911Ssimonvoid Camellia_cfb8_encrypt(const unsigned char *in, unsigned char *out, 115162911Ssimon const unsigned long length, const CAMELLIA_KEY *key, 116162911Ssimon unsigned char *ivec, int *num, const int enc); 117162911Ssimonvoid Camellia_cfbr_encrypt_block(const unsigned char *in,unsigned char *out, 118162911Ssimon const int nbits,const CAMELLIA_KEY *key, 119162911Ssimon unsigned char *ivec,const int enc); 120162911Ssimonvoid Camellia_ofb128_encrypt(const unsigned char *in, unsigned char *out, 121162911Ssimon const unsigned long length, const CAMELLIA_KEY *key, 122162911Ssimon unsigned char *ivec, int *num); 123162911Ssimonvoid Camellia_ctr128_encrypt(const unsigned char *in, unsigned char *out, 124162911Ssimon const unsigned long length, const CAMELLIA_KEY *key, 125162911Ssimon unsigned char ivec[CAMELLIA_BLOCK_SIZE], 126162911Ssimon unsigned char ecount_buf[CAMELLIA_BLOCK_SIZE], 127162911Ssimon unsigned int *num); 128162911Ssimon 129162911Ssimon#ifdef __cplusplus 130162911Ssimon} 131162911Ssimon#endif 132162911Ssimon 133162911Ssimon#endif /* !HEADER_Camellia_H */ 134162911Ssimon 135