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)))) ; \
41 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
42 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
43 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
44 case 4: l1 =((unsigned long)(*(--(c)))) ; \
45 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
46 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
47 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
51 /* NOTE - c is not incremented as per l2n */
52 #define l2nn(l1,l2,c,n) { \
55 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
56 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
57 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
58 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
59 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
60 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
61 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
62 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
67 #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
68 l|=((unsigned long)(*((c)++)))<<16L, \
69 l|=((unsigned long)(*((c)++)))<< 8L, \
70 l|=((unsigned long)(*((c)++))))
73 #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
74 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
75 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
76 *((c)++)=(unsigned char)(((l) )&0xff))
79 #define s2n(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
80 *((c)++)=(unsigned char)(((l)>> 8L)&0xff))
83 #define n2s(c,l) (l =((IDEA_INT)(*((c)++)))<< 8L, \
84 l|=((IDEA_INT)(*((c)++))) )
89 idea_mul(x1,x1,*p,ul); p++; \
93 idea_mul(x4,x4,*p,ul); p++; \
95 idea_mul(t0,t0,*p,ul); p++; \
96 t1=(t0+(x2^x4))&0xffff; \
97 idea_mul(t1,t1,*p,ul); p++; \
101 ul=x2^t0; /* do the swap to x3 */ \