Go to the documentation of this file.
112 #ifndef HEADER_BN_LCL_H
113 #define HEADER_BN_LCL_H
115 #if defined( INC_ALL )
154 #define BN_window_bits_for_exponent_size(b) \
164 #define BN_window_bits_for_exponent_size(b) \
176 #define MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH ( 64 )
177 #define MOD_EXP_CTIME_MIN_CACHE_LINE_MASK (MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH - 1)
191 #if MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH == 64
193 # define BN_window_bits_for_ctime_exponent_size(b) \
198 # define BN_MAX_WINDOW_BITS_FOR_CTIME_EXPONENT_SIZE (6)
200 #elif MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH == 32
202 # define BN_window_bits_for_ctime_exponent_size(b) \
206 # define BN_MAX_WINDOW_BITS_FOR_CTIME_EXPONENT_SIZE (5)
213 #define BN_MULL_SIZE_NORMAL (16)
214 #define BN_MUL_RECURSIVE_SIZE_NORMAL (16)
215 #define BN_SQR_RECURSIVE_SIZE_NORMAL (16)
216 #define BN_MUL_LOW_RECURSIVE_SIZE_NORMAL (32)
217 #define BN_MONT_CTX_SET_SIZE_WORD (64)
219 #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
243 # if defined(__alpha) && (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT))
246 # define BN_UMULT_HIGH(a,b) (BN_ULONG)asm("umulh %a0,%a1,%v0",(a),(b))
247 # elif defined(__GNUC__)
248 # define BN_UMULT_HIGH(a,b) ({ \
249 register BN_ULONG ret; \
250 asm ("umulh %1,%2,%0" \
255 # elif defined(_ARCH_PPC) && defined(__64BIT__) && defined(SIXTY_FOUR_BIT_LONG)
256 # if defined(__GNUC__)
257 # define BN_UMULT_HIGH(a,b) ({ \
258 register BN_ULONG ret; \
259 asm ("mulhdu %0,%1,%2" \
264 # elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG)
265 # if defined(__GNUC__)
266 # define BN_UMULT_HIGH(a,b) ({ \
267 register BN_ULONG ret,discard; \
269 : "=a"(discard),"=d"(ret) \
273 # define BN_UMULT_LOHI(low,high,a,b) \
275 : "=a"(low),"=d"(high) \
279 # elif (defined(_M_AMD64) || defined(_M_X64)) && defined(SIXTY_FOUR_BIT)
280 # if defined(_MSC_VER) && _MSC_VER>=1400
281 unsigned __int64 __umulh (
unsigned __int64 a,
unsigned __int64 b);
282 unsigned __int64 _umul128 (
unsigned __int64 a,
unsigned __int64 b,
283 unsigned __int64 *h);
284 # pragma intrinsic(__umulh,_umul128)
285 # define BN_UMULT_HIGH(a,b) __umulh((a),(b))
286 # define BN_UMULT_LOHI(low,high,a,b) ((low)=_umul128((a),(b),&(high)))
294 #define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
295 #define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
298 #define bn_clear_top2max(a) \
300 int ind = (a)->dmax - (a)->top; \
301 BN_ULONG *ftl = &(a)->d[(a)->top-1]; \
302 for (; ind != 0; ind--) \
306 #define bn_clear_top2max(a)
310 #define mul_add(r,a,w,c) { \
312 t=(BN_ULLONG)w * (a) + (r) + (c); \
317 #define mul(r,a,w,c) { \
319 t=(BN_ULLONG)w * (a) + (c); \
324 #define sqr(r0,r1,a) { \
326 t=(BN_ULLONG)(a)*(a); \
331 #elif defined(BN_UMULT_HIGH)
332 #define mul_add(r,a,w,c) { \
333 BN_ULONG high,low,ret,tmp=(a); \
335 high= BN_UMULT_HIGH(w,tmp); \
338 (c) = (ret<(c))?1:0; \
341 (c) += (ret<low)?1:0; \
345 #define mul(r,a,w,c) { \
346 BN_ULONG high,low,ret,ta=(a); \
348 high= BN_UMULT_HIGH(w,ta); \
351 (c) += (ret<low)?1:0; \
355 #define sqr(r0,r1,a) { \
358 (r1) = BN_UMULT_HIGH(tmp,tmp); \
366 #define LBITS(a) ((a)&BN_MASK2l)
367 #define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l)
368 #define L2HBITS(a) (((a)<<BN_BITS4)&BN_MASK2)
370 #define LLBITS(a) ((a)&BN_MASKl)
371 #define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl)
372 #define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2)
374 #define mul64(l,h,bl,bh) \
376 BN_ULONG m,m1,lt,ht; \
384 m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS((BN_ULONG)1); \
387 lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \
392 #define sqr64(lo,ho,in) \
402 h+=(m&BN_MASK2h1)>>(BN_BITS4-1); \
403 m =(m&BN_MASK2l)<<(BN_BITS4+1); \
404 l=(l+m)&BN_MASK2; if (l < m) h++; \
409 #define mul_add(r,a,bl,bh,c) { \
415 mul64(l,h,(bl),(bh)); \
418 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
420 l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
425 #define mul(r,a,bl,bh,c) { \
431 mul64(l,h,(bl),(bh)); \
434 l+=(c); if ((l&BN_MASK2) < (c)) h++; \