2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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
11 * The new form of this macro (check if the a*b == 0) was suggested by Colin
12 * Plumb <colin@nyx10.cs.du.edu>
14 /* Removal of the inner if from from Wei Dai 24/4/96 */
15 #define idea_mul(r,a,b,ul) \
16 ul=(unsigned long)a*b; \
19 r=(ul&0xffff)-(ul>>16); \
23 r=(-(int)a-b+1); /* assuming a or b is 0 and in range */
26 * 7/12/95 - Many thanks to Rhys Weatherley <rweather@us.oracle.com> for
27 * pointing out that I was assuming little endian byte order for all
28 * quantities what idea actually used bigendian. No where in the spec does
29 * it mention this, it is all in terms of 16 bit numbers and even the example
30 * does not use byte streams for the input example :-(. If you byte swap each
31 * pair of input, keys and iv, the functions would produce the output as the
35 /* NOTE - c is not incremented as per n2l */
36 #define n2ln(c,l1,l2,n) { \
40 case 8: l2 =((unsigned long)(*(--(c)))) ; \
42 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
44 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
46 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
48 case 4: l1 =((unsigned long)(*(--(c)))) ; \
50 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
52 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
54 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
58 /* NOTE - c is not incremented as per l2n */
59 #define l2nn(l1,l2,c,n) { \
62 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
64 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
66 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
68 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
70 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
72 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
74 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
76 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
81 #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
82 l|=((unsigned long)(*((c)++)))<<16L, \
83 l|=((unsigned long)(*((c)++)))<< 8L, \
84 l|=((unsigned long)(*((c)++))))
87 #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
88 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
89 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
90 *((c)++)=(unsigned char)(((l) )&0xff))
93 #define s2n(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
94 *((c)++)=(unsigned char)(((l)>> 8L)&0xff))
97 #define n2s(c,l) (l =((IDEA_INT)(*((c)++)))<< 8L, \
98 l|=((IDEA_INT)(*((c)++))) )
101 #define E_IDEA(num) \
103 idea_mul(x1,x1,*p,ul); p++; \
107 idea_mul(x4,x4,*p,ul); p++; \
109 idea_mul(t0,t0,*p,ul); p++; \
110 t1=(t0+(x2^x4))&0xffff; \
111 idea_mul(t1,t1,*p,ul); p++; \
115 ul=x2^t0; /* do the swap to x3 */ \