1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10#ifndef OSSL_CRYPTO_BF_LOCAL_H
11# define OSSL_CRYPTO_BF_LOCAL_H
12# include <openssl/opensslconf.h>
13
14/* NOTE - c is not incremented as per n2l */
15# define n2ln(c,l1,l2,n) { \
16 c+=n; \
17 l1=l2=0; \
18 switch (n) { \
19 case 8: l2 =((unsigned long)(*(--(c)))) ; \
20 /* fall thru */ \
21 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
22 /* fall thru */ \
23 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
24 /* fall thru */ \
25 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
26 /* fall thru */ \
27 case 4: l1 =((unsigned long)(*(--(c)))) ; \
28 /* fall thru */ \
29 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
30 /* fall thru */ \
31 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
32 /* fall thru */ \
33 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
34 } \
35 }
36
37/* NOTE - c is not incremented as per l2n */
38# define l2nn(l1,l2,c,n) { \
39 c+=n; \
40 switch (n) { \
41 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
42 /* fall thru */ \
43 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
44 /* fall thru */ \
45 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
46 /* fall thru */ \
47 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
48 /* fall thru */ \
49 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
50 /* fall thru */ \
51 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
52 /* fall thru */ \
53 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
54 /* fall thru */ \
55 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
56 } \
57 }
58
59# undef n2l
60# define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
61 l|=((unsigned long)(*((c)++)))<<16L, \
62 l|=((unsigned long)(*((c)++)))<< 8L, \
63 l|=((unsigned long)(*((c)++))))
64
65# undef l2n
66# define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
67 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
68 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
69 *((c)++)=(unsigned char)(((l) )&0xff))
70
71/*
72 * This is actually a big endian algorithm, the most significant byte is used
73 * to lookup array 0
74 */
75
76# define BF_ENC(LL,R,S,P) ( \
77 LL^=P, \
78 LL^=((( S[ ((R>>24)&0xff)] + \
79 S[0x0100+((R>>16)&0xff)])^ \
80 S[0x0200+((R>> 8)&0xff)])+ \
81 S[0x0300+((R )&0xff)])&0xffffffffU \
82 )
83
84#endif
85