]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_apple_csp/open_ssl/bn/exp.c
Security-57740.1.18.tar.gz
[apple/security.git] / OSX / libsecurity_apple_csp / open_ssl / bn / exp.c
1 /*
2 * Copyright (c) 2000-2001,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /* unused */
20
21 #include <stdio.h>
22 #include <openssl/tmdiff.h>
23 #include "bn_lcl.h"
24
25 #define SIZE 256
26 #define NUM (8*8*8)
27 #define MOD (8*8*8*8*8)
28
29 main(argc,argv)
30 int argc;
31 char *argv[];
32 {
33 BN_CTX ctx;
34 BIGNUM a,b,c,r,rr,t,l;
35 int j,i,size=SIZE,num=NUM,mod=MOD;
36 char *start,*end;
37 BN_MONT_CTX mont;
38 double d,md;
39
40 BN_MONT_CTX_init(&mont);
41 BN_CTX_init(&ctx);
42 BN_init(&a);
43 BN_init(&b);
44 BN_init(&c);
45 BN_init(&r);
46
47 start=ms_time_new();
48 end=ms_time_new();
49 while (size <= 1024*8)
50 {
51 BN_rand(&a,size,0,0);
52 BN_rand(&b,size,1,0);
53 BN_rand(&c,size,0,1);
54
55 BN_mod(&a,&a,&c,&ctx);
56
57 ms_time_get(start);
58 for (i=0; i<10; i++)
59 BN_MONT_CTX_set(&mont,&c,&ctx);
60 ms_time_get(end);
61 md=ms_time_diff(start,end);
62
63 ms_time_get(start);
64 for (i=0; i<num; i++)
65 {
66 /* bn_mull(&r,&a,&b,&ctx); */
67 /* BN_sqr(&r,&a,&ctx); */
68 BN_mod_exp_mont(&r,&a,&b,&c,&ctx,&mont);
69 }
70 ms_time_get(end);
71 d=ms_time_diff(start,end)/* *50/33 */;
72 printf("%5d bit:%6.2f %6d %6.4f %4d m_set(%5.4f)\n",size,
73 d,num,d/num,(int)((d/num)*mod),md/10.0);
74 num/=8;
75 mod/=8;
76 if (num <= 0) num=1;
77 size*=2;
78 }
79
80 }