Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:14

0001 /* blowfish.h
0002 
0003    Blowfish block cipher.
0004 
0005    Copyright (C) 2014 Niels Möller
0006    Copyright (C) 1998, 2001 FSF, Ray Dassen, Niels Möller
0007 
0008    This file is part of GNU Nettle.
0009 
0010    GNU Nettle is free software: you can redistribute it and/or
0011    modify it under the terms of either:
0012 
0013      * the GNU Lesser General Public License as published by the Free
0014        Software Foundation; either version 3 of the License, or (at your
0015        option) any later version.
0016 
0017    or
0018 
0019      * the GNU General Public License as published by the Free
0020        Software Foundation; either version 2 of the License, or (at your
0021        option) any later version.
0022 
0023    or both in parallel, as here.
0024 
0025    GNU Nettle is distributed in the hope that it will be useful,
0026    but WITHOUT ANY WARRANTY; without even the implied warranty of
0027    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0028    General Public License for more details.
0029 
0030    You should have received copies of the GNU General Public License and
0031    the GNU Lesser General Public License along with this program.  If
0032    not, see http://www.gnu.org/licenses/.
0033 */
0034  
0035 #ifndef NETTLE_BLOWFISH_H_INCLUDED
0036 #define NETTLE_BLOWFISH_H_INCLUDED
0037 
0038 #include "nettle-types.h"
0039 
0040 #ifdef __cplusplus
0041 extern "C" {
0042 #endif
0043 
0044 /* Name mangling */
0045 #define blowfish_set_key nettle_blowfish_set_key
0046 #define blowfish128_set_key nettle_blowfish128_set_key
0047 #define blowfish_encrypt nettle_blowfish_encrypt
0048 #define blowfish_decrypt nettle_blowfish_decrypt
0049 #define blowfish_bcrypt_hash nettle_blowfish_bcrypt_hash
0050 #define blowfish_bcrypt_verify nettle_blowfish_bcrypt_verify
0051 
0052 #define BLOWFISH_BLOCK_SIZE 8
0053 
0054 /* Variable key size between 64 and 448 bits. */
0055 #define BLOWFISH_MIN_KEY_SIZE 8
0056 #define BLOWFISH_MAX_KEY_SIZE 56
0057 
0058 /* Default to 128 bits */
0059 #define BLOWFISH_KEY_SIZE 16
0060 
0061 #define BLOWFISH128_KEY_SIZE 16
0062 
0063 #define _BLOWFISH_ROUNDS 16
0064 
0065 #define BLOWFISH_BCRYPT_HASH_SIZE (60 + 1) /* Including null-terminator */
0066 #define BLOWFISH_BCRYPT_BINSALT_SIZE 16    /* Binary string size */
0067 
0068 struct blowfish_ctx
0069 {
0070   uint32_t s[4][256];
0071   uint32_t p[_BLOWFISH_ROUNDS+2];
0072 };
0073 
0074 /* Returns 0 for weak keys, otherwise 1. */
0075 int
0076 blowfish_set_key(struct blowfish_ctx *ctx,
0077                  size_t length, const uint8_t *key);
0078 int
0079 blowfish128_set_key(struct blowfish_ctx *ctx, const uint8_t *key);
0080 
0081 void
0082 blowfish_encrypt(const struct blowfish_ctx *ctx,
0083                  size_t length, uint8_t *dst,
0084                  const uint8_t *src);
0085 void
0086 blowfish_decrypt(const struct blowfish_ctx *ctx,
0087                  size_t length, uint8_t *dst,
0088                  const uint8_t *src);
0089 
0090 /* dst parameter must point to a buffer of minimally
0091  * BLOWFISH_BCRYPT_HASH_SIZE bytes */
0092 int
0093 blowfish_bcrypt_hash(uint8_t *dst,
0094                      size_t lenkey, const uint8_t *key,
0095                      size_t lenscheme, const uint8_t *scheme,
0096              int log2rounds,
0097              const uint8_t *salt);
0098 int
0099 blowfish_bcrypt_verify(size_t lenkey, const uint8_t *key,
0100                        size_t lenhashed, const uint8_t *hashed);
0101 
0102 #ifdef __cplusplus
0103 }
0104 #endif
0105 
0106 #endif /* NETTLE_BLOWFISH_H_INCLUDED */