Xuyi Wang / wolfcrypt

Dependents:   OS

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers idea.h Source File

idea.h

00001 /* idea.h
00002  *
00003  * Copyright (C) 2006-2017 wolfSSL Inc.
00004  *
00005  * This file is part of wolfSSL.
00006  *
00007  * wolfSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * wolfSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
00020  */
00021 
00022 /*!
00023     \file wolfssl/wolfcrypt/idea.h
00024 */
00025 
00026 #ifndef WOLF_CRYPT_IDEA_H
00027 #define WOLF_CRYPT_IDEA_H
00028 
00029 #include <wolfssl/wolfcrypt/types.h>
00030 
00031 #ifdef HAVE_IDEA
00032 
00033 #ifdef __cplusplus
00034     extern "C" {
00035 #endif
00036 
00037 enum {
00038     IDEA_MODULO     = 0x10001,             /* 2^16+1 */
00039     IDEA_2EXP16     = 0x10000,             /* 2^16 */
00040     IDEA_MASK       = 0xFFFF,              /* 16 bits set to one */
00041     IDEA_ROUNDS     = 8,                   /* number of rounds for IDEA */
00042     IDEA_SK_NUM     = (6*IDEA_ROUNDS + 4), /* number of subkeys */
00043     IDEA_KEY_SIZE   = 16,                  /* size of key in bytes */
00044     IDEA_BLOCK_SIZE = 8,                   /* size of IDEA blocks in bytes */
00045     IDEA_IV_SIZE    = 8,                   /* size of IDEA IV in bytes */
00046     IDEA_ENCRYPTION = 0,
00047     IDEA_DECRYPTION = 1
00048 };
00049 
00050 /* IDEA encryption and decryption */
00051 typedef struct Idea {
00052     word32  reg[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
00053     word32  tmp[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
00054     word16  skey[IDEA_SK_NUM]; /* 832 bits expanded key */
00055 } Idea;
00056 
00057 WOLFSSL_API int wc_IdeaSetKey(Idea *idea, const byte* key, word16 keySz,
00058                               const byte *iv, int dir);
00059 WOLFSSL_API int wc_IdeaSetIV(Idea *idea, const byte* iv);
00060 WOLFSSL_API int wc_IdeaCipher(Idea *idea, byte* out, const byte* in);
00061 WOLFSSL_API int wc_IdeaCbcEncrypt(Idea *idea, byte* out,
00062                                   const byte* in, word32 len);
00063 WOLFSSL_API int wc_IdeaCbcDecrypt(Idea *idea, byte* out,
00064                                   const byte* in, word32 len);
00065 #ifdef __cplusplus
00066     } /* extern "C" */
00067 #endif
00068 
00069 #endif /* HAVE_IDEA */
00070 #endif /* WOLF_CRYPT_IDEA_H */
00071