idea.h
Go to the documentation of this file.
1 /* idea.h
2  *
3  * Copyright (C) 2006-2020 wolfSSL Inc.
4  *
5  * This file is part of wolfSSL.
6  *
7  * wolfSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * wolfSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20  */
21 
26 #ifndef WOLF_CRYPT_IDEA_H
27 #define WOLF_CRYPT_IDEA_H
28 
30 
31 #ifdef HAVE_IDEA
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 enum {
38  IDEA_MODULO = 0x10001, /* 2^16+1 */
39  IDEA_2EXP16 = 0x10000, /* 2^16 */
40  IDEA_MASK = 0xFFFF, /* 16 bits set to one */
41  IDEA_ROUNDS = 8, /* number of rounds for IDEA */
42  IDEA_SK_NUM = (6*IDEA_ROUNDS + 4), /* number of subkeys */
43  IDEA_KEY_SIZE = 16, /* size of key in bytes */
44  IDEA_BLOCK_SIZE = 8, /* size of IDEA blocks in bytes */
45  IDEA_IV_SIZE = 8, /* size of IDEA IV in bytes */
46  IDEA_ENCRYPTION = 0,
47  IDEA_DECRYPTION = 1
48 };
49 
50 /* IDEA encryption and decryption */
51 typedef struct Idea {
52  word32 reg[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
53  word32 tmp[IDEA_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
54  word16 skey[IDEA_SK_NUM]; /* 832 bits expanded key */
55 } Idea;
56 
57 WOLFSSL_API int wc_IdeaSetKey(Idea *idea, const byte* key, word16 keySz,
58  const byte *iv, int dir);
59 WOLFSSL_API int wc_IdeaSetIV(Idea *idea, const byte* iv);
60 WOLFSSL_API int wc_IdeaCipher(Idea *idea, byte* out, const byte* in);
61 WOLFSSL_API int wc_IdeaCbcEncrypt(Idea *idea, byte* out,
62  const byte* in, word32 len);
63 WOLFSSL_API int wc_IdeaCbcDecrypt(Idea *idea, byte* out,
64  const byte* in, word32 len);
65 #ifdef __cplusplus
66  } /* extern "C" */
67 #endif
68 
69 #endif /* HAVE_IDEA */
70 #endif /* WOLF_CRYPT_IDEA_H */
WOLFSSL_API int wc_IdeaSetKey(Idea *idea, const byte *key, word16 keySz, const byte *iv, int dir)
Generate the 52, 16-bit key sub-blocks from the 128 key.
Definition: idea.c:118
WOLFSSL_API int wc_IdeaCbcEncrypt(Idea *idea, byte *out, const byte *in, word32 len)
Encrypt data using IDEA CBC mode.
Definition: idea.c:252
WOLFSSL_API int wc_IdeaCbcDecrypt(Idea *idea, byte *out, const byte *in, word32 len)
Decrypt data using IDEA CBC mode.
Definition: idea.c:277
Definition: idea.h:51
WOLFSSL_API int wc_IdeaCipher(Idea *idea, byte *out, const byte *in)
Encryption or decryption for a block (64 bits).
Definition: idea.c:197
WOLFSSL_API int wc_IdeaSetIV(Idea *idea, const byte *iv)
Sets the IV in an Idea key structure.
Definition: idea.c:182