yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* camellia.h ver 1.2.0 |
| 2 | * |
| 3 | * Copyright (c) 2006,2007 |
| 4 | * NTT (Nippon Telegraph and Telephone Corporation) . All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer as |
| 11 | * the first lines of this file unmodified. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY NTT ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 19 | * IN NO EVENT SHALL NTT BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | /* camellia.h |
| 29 | * |
| 30 | * Copyright (C) 2006-2021 wolfSSL Inc. |
| 31 | * |
| 32 | * This file is part of wolfSSL. |
| 33 | * |
| 34 | * wolfSSL is free software; you can redistribute it and/or modify |
| 35 | * it under the terms of the GNU General Public License as published by |
| 36 | * the Free Software Foundation; either version 2 of the License, or |
| 37 | * (at your option) any later version. |
| 38 | * |
| 39 | * wolfSSL is distributed in the hope that it will be useful, |
| 40 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 41 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 42 | * GNU General Public License for more details. |
| 43 | * |
| 44 | * You should have received a copy of the GNU General Public License |
| 45 | * along with this program; if not, write to the Free Software |
| 46 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
| 47 | */ |
| 48 | |
| 49 | /*! |
| 50 | \file wolfssl/wolfcrypt/camellia.h |
| 51 | */ |
| 52 | |
| 53 | |
| 54 | #ifndef WOLF_CRYPT_CAMELLIA_H |
| 55 | #define WOLF_CRYPT_CAMELLIA_H |
| 56 | |
| 57 | #include <wolfssl/wolfcrypt/types.h> |
| 58 | |
| 59 | #ifdef HAVE_CAMELLIA |
| 60 | |
| 61 | #ifdef __cplusplus |
| 62 | extern "C" { |
| 63 | #endif |
| 64 | |
| 65 | enum { |
| 66 | CAMELLIA_BLOCK_SIZE = 16 |
| 67 | }; |
| 68 | |
| 69 | #define CAMELLIA_TABLE_BYTE_LEN 272 |
| 70 | #define CAMELLIA_TABLE_WORD_LEN (CAMELLIA_TABLE_BYTE_LEN / sizeof(word32)) |
| 71 | |
| 72 | typedef word32 KEY_TABLE_TYPE[CAMELLIA_TABLE_WORD_LEN]; |
| 73 | |
| 74 | typedef struct Camellia { |
| 75 | word32 keySz; |
| 76 | KEY_TABLE_TYPE key; |
| 77 | word32 reg[CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ |
| 78 | word32 tmp[CAMELLIA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */ |
| 79 | } Camellia; |
| 80 | |
| 81 | |
| 82 | WOLFSSL_API int wc_CamelliaSetKey(Camellia* cam, |
| 83 | const byte* key, word32 len, const byte* iv); |
| 84 | WOLFSSL_API int wc_CamelliaSetIV(Camellia* cam, const byte* iv); |
| 85 | WOLFSSL_API int wc_CamelliaEncryptDirect(Camellia* cam, byte* out, |
| 86 | const byte* in); |
| 87 | WOLFSSL_API int wc_CamelliaDecryptDirect(Camellia* cam, byte* out, |
| 88 | const byte* in); |
| 89 | WOLFSSL_API int wc_CamelliaCbcEncrypt(Camellia* cam, |
| 90 | byte* out, const byte* in, word32 sz); |
| 91 | WOLFSSL_API int wc_CamelliaCbcDecrypt(Camellia* cam, |
| 92 | byte* out, const byte* in, word32 sz); |
| 93 | |
| 94 | |
| 95 | #ifdef __cplusplus |
| 96 | } /* extern "C" */ |
| 97 | #endif |
| 98 | |
| 99 | #endif /* HAVE_CAMELLIA */ |
| 100 | #endif /* WOLF_CRYPT_CAMELLIA_H */ |
| 101 | |