]> git.cryptolib.org Git - avr-crypto-lib.git/blob - cast5.h
2b1d31701fcf82f7c70fa5f327964fee79116598
[avr-crypto-lib.git] / cast5.h
1 /* cast5.h */
2 /*
3     This file is part of the Crypto-avr-lib/microcrypt-lib.
4     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
5
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.
10
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.
15
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/>.
18 */
19 /* 
20  * File:        cast5.h
21  * Author:      Daniel Otte
22  * Date:        2006-07-26
23  * License: GPL
24  * Description: Implementation of the CAST5 (aka CAST-128) cipher algorithm as described in RFC 2144
25  * 
26  */
27
28 /** 
29  * \file        cast5.h
30  * \author      Daniel Otte
31  * \date        2006-07-26
32  * \license GPL
33  * \brief Implementation of the CAST5 (aka CAST-128) cipher algorithm as described in RFC 2144
34  * 
35  */
36
37 #ifndef CAST5_H_
38 #define CAST5_H_ 
39
40 #include <stdint.h> 
41
42 #ifndef BOOL
43 #define BOOL
44  #ifndef __BOOL
45  #define __BOOL
46   #ifndef __BOOL__
47   #define __BOOL__
48         typedef enum{false=0,true=1} bool;
49   #endif
50  #endif
51 #endif
52
53 /** \typedef cast5_ctx_t
54  * \brief CAST-5 context
55  * 
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.
59  */
60 typedef struct cast5_ctx_st{
61         uint32_t        mask[16];
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 */
64         bool            shortkey;
65 } cast5_ctx_t;
66
67
68 /** \fn void cast5_init(void* key, uint8_t keylength_b, cast5_ctx_t* s);
69  * \brief generate keyschedule/contex for CAST-5
70  * 
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
76  */
77 void cast5_init(const void* key, uint8_t keylength_b, cast5_ctx_t* s);
78
79 /** \fn void cast5_enc(void* block, const cast5_ctx_t *s);
80  * \brief encrypt a block with the CAST-5 algorithm
81  * 
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
87  */
88 void cast5_enc(void* block, const cast5_ctx_t *s);
89
90 /** \fn void cast5_dec(void* block, const cast5_ctx_t *s);
91  * \brief decrypt a block with the CAST-5 algorithm
92  * 
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
98  */
99 void cast5_dec(void* block, const cast5_ctx_t *s);
100
101
102
103 #endif
104