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