This repository has been archived by the owner on Sep 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
bf.h
106 lines (89 loc) · 3.04 KB
/
bf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
Bruce Schneier's Blowfish.
Author: Olaf Titz <[email protected]>
This code is in the public domain.
$Id: bf.h,v 1.5 2003/01/15 22:01:57 olaf81825 Exp $
*/
#ifndef _BF_H_
#define _BF_H_
#include "bf_config.h"
/* PORTABILITY: under non-Linux,
omit this include and insert an appropriate typedef
*/
//#include <asm/types.h> /* gives __u32 as an unsigned 32bit integer */
#include <stdint.h> /* gives uint32_t as an unsigned 32bit integer */
//# include <asm/byteorder.h>
/* PORTABILITY: under non-Linux, omit this include.
Generic, endian-neutral, slower C routines will be used instead of
the assembler versions found in the kernel includes.
*/
/* This is ugly, but seems the easiest way to find an endianness test
which works both in kernel and user mode.
This is only an optimization - everything works even if none of the
tests are defined.
*/
#ifdef __BYTE_ORDER
#if __BYTE_ORDER == __BIG_ENDIAN
#define BF_NATIVE_BE
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define BF_NATIVE_LE
#endif
#else
#ifdef __BIG_ENDIAN
#define BF_NATIVE_BE
#endif
#ifdef __LITTLE_ENDIAN
#define BF_NATIVE_LE
#endif
#endif
/* The data block processed by the encryption algorithm - 64 bits */
typedef uint32_t Blowfish_Data[2];
/* The key as entered by the user - size may vary */
typedef char Blowfish_UserKey[16];
/* The expanded key for internal use - 18+4*256 words*/
typedef uint32_t Blowfish_Key[1042];
/* Byteorder-dependent handling of data encryption: Blowfish is by
definition big-endian. However, there are broken implementations on
little-endian machines which treat the data as little-endian.
This module provides both variants.
*/
#ifndef BF_DONTNEED_BE
/* Big endian. This is the "real" Blowfish. */
#ifdef BF_NATIVE_BE
#undef BF_DONTNEED_N
#define B_Blowfish_Encrypt _N_Blowfish_Encrypt
#define B_Blowfish_Decrypt _N_Blowfish_Decrypt
#else
extern void B_Blowfish_Encrypt(uint32_t *dataIn, uint32_t *dataOut,
const Blowfish_Key key);
extern void B_Blowfish_Decrypt(uint32_t *dataIn, uint32_t *dataOut,
const Blowfish_Key key);
#endif
#endif
#ifndef BF_DONTNEED_LE
/* Little endian. To be compatible with other LE implementations. */
#ifdef BF_NATIVE_LE
#undef BF_DONTNEED_N
#define L_Blowfish_Encrypt _N_Blowfish_Encrypt
#define L_Blowfish_Decrypt _N_Blowfish_Decrypt
#else
extern void L_Blowfish_Encrypt(uint32_t *dataIn, uint32_t *dataOut,
const Blowfish_Key key);
extern void L_Blowfish_Decrypt(uint32_t *dataIn, uint32_t *dataOut,
const Blowfish_Key key);
#endif
#endif
#ifndef BF_DONTNEED_N
/* Native byte order. For internal use ONLY. */
extern void _N_Blowfish_Encrypt(uint32_t *dataIn, uint32_t *dataOut,
const Blowfish_Key key);
extern void _N_Blowfish_Decrypt(uint32_t *dataIn, uint32_t *dataOut,
const Blowfish_Key key);
#endif
/* User key expansion. This is not byteorder dependent as all common
implementations get it right (i.e. big-endian). */
extern void Blowfish_ExpandUserKey(const char *userKey, int userKeyLen,
Blowfish_Key key);
extern const Blowfish_Key Blowfish_Init_Key;
#endif