| 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 |
{ \ |
| 17 |
c += n; \ |
| 18 |
l1 = l2 = 0; \ |
| 19 |
switch (n) { \ |
| 20 |
case 8: \ |
| 21 |
l2 = ((unsigned long)(*(--(c)))); \ |
| 22 |
/* fall through */ \ |
| 23 |
case 7: \ |
| 24 |
l2 |= ((unsigned long)(*(--(c)))) << 8; \ |
| 25 |
/* fall through */ \ |
| 26 |
case 6: \ |
| 27 |
l2 |= ((unsigned long)(*(--(c)))) << 16; \ |
| 28 |
/* fall through */ \ |
| 29 |
case 5: \ |
| 30 |
l2 |= ((unsigned long)(*(--(c)))) << 24; \ |
| 31 |
/* fall through */ \ |
| 32 |
case 4: \ |
| 33 |
l1 = ((unsigned long)(*(--(c)))); \ |
| 34 |
/* fall through */ \ |
| 35 |
case 3: \ |
| 36 |
l1 |= ((unsigned long)(*(--(c)))) << 8; \ |
| 37 |
/* fall through */ \ |
| 38 |
case 2: \ |
| 39 |
l1 |= ((unsigned long)(*(--(c)))) << 16; \ |
| 40 |
/* fall through */ \ |
| 41 |
case 1: \ |
| 42 |
l1 |= ((unsigned long)(*(--(c)))) << 24; \ |
| 43 |
} \ |
| 44 |
} |
| 45 |
|
| 46 |
/* NOTE - c is not incremented as per l2n */ |
| 47 |
#define l2nn(l1, l2, c, n) \ |
| 48 |
{ \ |
| 49 |
c += n; \ |
| 50 |
switch (n) { \ |
| 51 |
case 8: \ |
| 52 |
*(--(c)) = (unsigned char)(((l2)) & 0xff); \ |
| 53 |
/* fall through */ \ |
| 54 |
case 7: \ |
| 55 |
*(--(c)) = (unsigned char)(((l2) >> 8) & 0xff); \ |
| 56 |
/* fall through */ \ |
| 57 |
case 6: \ |
| 58 |
*(--(c)) = (unsigned char)(((l2) >> 16) & 0xff); \ |
| 59 |
/* fall through */ \ |
| 60 |
case 5: \ |
| 61 |
*(--(c)) = (unsigned char)(((l2) >> 24) & 0xff); \ |
| 62 |
/* fall through */ \ |
| 63 |
case 4: \ |
| 64 |
*(--(c)) = (unsigned char)(((l1)) & 0xff); \ |
| 65 |
/* fall through */ \ |
| 66 |
case 3: \ |
| 67 |
*(--(c)) = (unsigned char)(((l1) >> 8) & 0xff); \ |
| 68 |
/* fall through */ \ |
| 69 |
case 2: \ |
| 70 |
*(--(c)) = (unsigned char)(((l1) >> 16) & 0xff); \ |
| 71 |
/* fall through */ \ |
| 72 |
case 1: \ |
| 73 |
*(--(c)) = (unsigned char)(((l1) >> 24) & 0xff); \ |
| 74 |
} \ |
| 75 |
} |
| 76 |
|
| 77 |
#undef n2l |
| 78 |
#define n2l(c, l) (l = ((unsigned long)(*((c)++))) << 24L, \ |
| 79 |
l |= ((unsigned long)(*((c)++))) << 16L, \ |
| 80 |
l |= ((unsigned long)(*((c)++))) << 8L, \ |
| 81 |
l |= ((unsigned long)(*((c)++)))) |
| 82 |
|
| 83 |
#undef l2n |
| 84 |
#define l2n(l, c) (*((c)++) = (unsigned char)(((l) >> 24L) & 0xff), \ |
| 85 |
*((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \ |
| 86 |
*((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \ |
| 87 |
*((c)++) = (unsigned char)(((l)) & 0xff)) |
| 88 |
|
| 89 |
/* |
| 90 |
* This is actually a big endian algorithm, the most significant byte is used |
| 91 |
* to lookup array 0 |
| 92 |
*/ |
| 93 |
|
| 94 |
#define BF_ENC(LL, R, S, P) ( \ |
| 95 |
LL ^= P, \ |
| 96 |
LL ^= (((S[((R >> 24) & 0xff)] + S[0x0100 + ((R >> 16) & 0xff)]) ^ S[0x0200 + ((R >> 8) & 0xff)]) + S[0x0300 + ((R) & 0xff)]) & 0xffffffffU) |
| 97 |
|
| 98 |
#endif |