2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
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
10 #define idea_mul(r,a,b,ul) \
11 ul=(unsigned long)a*b; \
14 r=(ul&0xffff)-(ul>>16); \
18 r=(-(int)a-b+1); /* assuming a or b is 0 and in range */
20 /* NOTE - c is not incremented as per n2l */
21 #define n2ln(c,l1,l2,n) { \
25 case 8: l2 =((unsigned long)(*(--(c)))) ; \
27 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
29 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
31 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
33 case 4: l1 =((unsigned long)(*(--(c)))) ; \
35 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
37 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
39 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
43 /* NOTE - c is not incremented as per l2n */
44 #define l2nn(l1,l2,c,n) { \
47 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
49 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
51 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
53 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
55 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
57 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
59 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
61 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
66 #define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
67 l|=((unsigned long)(*((c)++)))<<16L, \
68 l|=((unsigned long)(*((c)++)))<< 8L, \
69 l|=((unsigned long)(*((c)++))))
72 #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
73 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
74 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
75 *((c)++)=(unsigned char)(((l) )&0xff))
78 #define s2n(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
79 *((c)++)=(unsigned char)(((l)>> 8L)&0xff))
82 #define n2s(c,l) (l =((IDEA_INT)(*((c)++)))<< 8L, \
83 l|=((IDEA_INT)(*((c)++))) )
88 idea_mul(x1,x1,*p,ul); p++; \
92 idea_mul(x4,x4,*p,ul); p++; \
94 idea_mul(t0,t0,*p,ul); p++; \
95 t1=(t0+(x2^x4))&0xffff; \
96 idea_mul(t1,t1,*p,ul); p++; \
100 ul=x2^t0; /* do the swap to x3 */ \