3 This file is part of the Crypto-avr-lib/microcrypt-lib.
4 Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * Description: Implementation of the CAST5 (aka CAST-128) cipher algorithm as described in RFC 2144
33 * \brief Implementation of the CAST5 (aka CAST-128) cipher algorithm as described in RFC 2144
48 typedef enum{false=0,true=1} bool;
53 /** \typedef cast5_ctx_t
54 * \brief CAST-5 context
56 * A variable of this type may hold a keyschedule for the CAST-5 cipher.
57 * This context is regulary generated by the
58 * cast5_init(uint8_t* key, uint8_t keylength_b, cast5_ctx_t* s) function.
60 typedef struct cast5_ctx_st{
62 uint8_t rotl[8]; /* 4 bit from every rotation key is stored here */
63 uint8_t roth[2]; /* 1 bit from every rotation key is stored here */
68 /** \fn void cast5_init(void* key, uint8_t keylength_b, cast5_ctx_t* s);
69 * \brief generate keyschedule/contex for CAST-5
71 * This function generates the keyschedule from the supplied key for the
72 * CAST-5 cipher and stores it in a supplied ::cast5_ctx_t context.
73 * \param key pointer to the key
74 * \param keylength_b length of the key in bits (maximum 128 bits)
75 * \param s pointer to the context
77 void cast5_init(const void* key, uint8_t keylength_b, cast5_ctx_t* s);
79 /** \fn void cast5_enc(void* block, const cast5_ctx_t *s);
80 * \brief encrypt a block with the CAST-5 algorithm
82 * This function encrypts a block of 64 bits (8 bytes) with the CAST-5 algorithm.
83 * It uses a keyschedule as generated by the
84 * cast5_init(void* key, uint8_t keylength_b, cast5_ctx_t* s) function.
85 * \param block pointer to the block which gets encrypted
86 * \param s pointer to the keyschedule/context
88 void cast5_enc(void* block, const cast5_ctx_t *s);
90 /** \fn void cast5_dec(void* block, const cast5_ctx_t *s);
91 * \brief decrypt a block with the CAST-5 algorithm
93 * This function decrypts a block of 64 bits (8 bytes) with the CAST-5 algorithm.
94 * It uses a keyschedule as generated by the
95 * cast5_init(void* key, uint8_t keylength_b, cast5_ctx_t* s) function.
96 * \param block pointer to the block which gets decrypted
97 * \param s pointer to the keyschedule/context
99 void cast5_dec(void* block, const cast5_ctx_t *s);