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#define idea_mul(r,a,b,ul) \ 11e1051a39Sopenharmony_ciul=(unsigned long)a*b; \ 12e1051a39Sopenharmony_ciif (ul != 0) \ 13e1051a39Sopenharmony_ci { \ 14e1051a39Sopenharmony_ci r=(ul&0xffff)-(ul>>16); \ 15e1051a39Sopenharmony_ci r-=((r)>>16); \ 16e1051a39Sopenharmony_ci } \ 17e1051a39Sopenharmony_cielse \ 18e1051a39Sopenharmony_ci r=(-(int)a-b+1); /* assuming a or b is 0 and in range */ 19e1051a39Sopenharmony_ci 20e1051a39Sopenharmony_ci/* NOTE - c is not incremented as per n2l */ 21e1051a39Sopenharmony_ci#define n2ln(c,l1,l2,n) { \ 22e1051a39Sopenharmony_ci c+=n; \ 23e1051a39Sopenharmony_ci l1=l2=0; \ 24e1051a39Sopenharmony_ci switch (n) { \ 25e1051a39Sopenharmony_ci case 8: l2 =((unsigned long)(*(--(c)))) ; \ 26e1051a39Sopenharmony_ci /* fall thru */ \ 27e1051a39Sopenharmony_ci case 7: l2|=((unsigned long)(*(--(c))))<< 8; \ 28e1051a39Sopenharmony_ci /* fall thru */ \ 29e1051a39Sopenharmony_ci case 6: l2|=((unsigned long)(*(--(c))))<<16; \ 30e1051a39Sopenharmony_ci /* fall thru */ \ 31e1051a39Sopenharmony_ci case 5: l2|=((unsigned long)(*(--(c))))<<24; \ 32e1051a39Sopenharmony_ci /* fall thru */ \ 33e1051a39Sopenharmony_ci case 4: l1 =((unsigned long)(*(--(c)))) ; \ 34e1051a39Sopenharmony_ci /* fall thru */ \ 35e1051a39Sopenharmony_ci case 3: l1|=((unsigned long)(*(--(c))))<< 8; \ 36e1051a39Sopenharmony_ci /* fall thru */ \ 37e1051a39Sopenharmony_ci case 2: l1|=((unsigned long)(*(--(c))))<<16; \ 38e1051a39Sopenharmony_ci /* fall thru */ \ 39e1051a39Sopenharmony_ci case 1: l1|=((unsigned long)(*(--(c))))<<24; \ 40e1051a39Sopenharmony_ci } \ 41e1051a39Sopenharmony_ci } 42e1051a39Sopenharmony_ci 43e1051a39Sopenharmony_ci/* NOTE - c is not incremented as per l2n */ 44e1051a39Sopenharmony_ci#define l2nn(l1,l2,c,n) { \ 45e1051a39Sopenharmony_ci c+=n; \ 46e1051a39Sopenharmony_ci switch (n) { \ 47e1051a39Sopenharmony_ci case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \ 48e1051a39Sopenharmony_ci /* fall thru */ \ 49e1051a39Sopenharmony_ci case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \ 50e1051a39Sopenharmony_ci /* fall thru */ \ 51e1051a39Sopenharmony_ci case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \ 52e1051a39Sopenharmony_ci /* fall thru */ \ 53e1051a39Sopenharmony_ci case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \ 54e1051a39Sopenharmony_ci /* fall thru */ \ 55e1051a39Sopenharmony_ci case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \ 56e1051a39Sopenharmony_ci /* fall thru */ \ 57e1051a39Sopenharmony_ci case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \ 58e1051a39Sopenharmony_ci /* fall thru */ \ 59e1051a39Sopenharmony_ci case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \ 60e1051a39Sopenharmony_ci /* fall thru */ \ 61e1051a39Sopenharmony_ci case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \ 62e1051a39Sopenharmony_ci } \ 63e1051a39Sopenharmony_ci } 64e1051a39Sopenharmony_ci 65e1051a39Sopenharmony_ci#undef n2l 66e1051a39Sopenharmony_ci#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \ 67e1051a39Sopenharmony_ci l|=((unsigned long)(*((c)++)))<<16L, \ 68e1051a39Sopenharmony_ci l|=((unsigned long)(*((c)++)))<< 8L, \ 69e1051a39Sopenharmony_ci l|=((unsigned long)(*((c)++)))) 70e1051a39Sopenharmony_ci 71e1051a39Sopenharmony_ci#undef l2n 72e1051a39Sopenharmony_ci#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ 73e1051a39Sopenharmony_ci *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ 74e1051a39Sopenharmony_ci *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ 75e1051a39Sopenharmony_ci *((c)++)=(unsigned char)(((l) )&0xff)) 76e1051a39Sopenharmony_ci 77e1051a39Sopenharmony_ci#undef s2n 78e1051a39Sopenharmony_ci#define s2n(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ 79e1051a39Sopenharmony_ci *((c)++)=(unsigned char)(((l)>> 8L)&0xff)) 80e1051a39Sopenharmony_ci 81e1051a39Sopenharmony_ci#undef n2s 82e1051a39Sopenharmony_ci#define n2s(c,l) (l =((IDEA_INT)(*((c)++)))<< 8L, \ 83e1051a39Sopenharmony_ci l|=((IDEA_INT)(*((c)++))) ) 84e1051a39Sopenharmony_ci 85e1051a39Sopenharmony_ci 86e1051a39Sopenharmony_ci#define E_IDEA(num) \ 87e1051a39Sopenharmony_ci x1&=0xffff; \ 88e1051a39Sopenharmony_ci idea_mul(x1,x1,*p,ul); p++; \ 89e1051a39Sopenharmony_ci x2+= *(p++); \ 90e1051a39Sopenharmony_ci x3+= *(p++); \ 91e1051a39Sopenharmony_ci x4&=0xffff; \ 92e1051a39Sopenharmony_ci idea_mul(x4,x4,*p,ul); p++; \ 93e1051a39Sopenharmony_ci t0=(x1^x3)&0xffff; \ 94e1051a39Sopenharmony_ci idea_mul(t0,t0,*p,ul); p++; \ 95e1051a39Sopenharmony_ci t1=(t0+(x2^x4))&0xffff; \ 96e1051a39Sopenharmony_ci idea_mul(t1,t1,*p,ul); p++; \ 97e1051a39Sopenharmony_ci t0+=t1; \ 98e1051a39Sopenharmony_ci x1^=t1; \ 99e1051a39Sopenharmony_ci x4^=t0; \ 100e1051a39Sopenharmony_ci ul=x2^t0; /* do the swap to x3 */ \ 101e1051a39Sopenharmony_ci x2=x3^t1; \ 102e1051a39Sopenharmony_ci x3=ul; 103