1 diff -Nur openssl-0.9.8h/Configure openssl-0.9.8h-ocf/Configure
2 --- openssl-0.9.8h/Configure 2008-05-02 01:11:30.000000000 +0200
3 +++ openssl-0.9.8h-ocf/Configure 2008-07-12 04:18:53.000000000 +0200
5 # (Default: KRB5_DIR/include)
6 # --with-krb5-flavor Declare what flavor of Kerberos 5 is used. Currently
7 # supported values are "MIT" and "Heimdal". A value is required.
8 +# --with-cryptodev Force support for cryptodev (ie., ocf-linux)
9 +# --with-cryptodev-digests Force support for cryptodev digests (generally slow)
11 # --test-sanity Make a number of sanity checks on the data in this file.
12 # This is a debugging tool for OpenSSL developers.
14 ##### Compaq Non-Stop Kernel (Tandem)
15 "tandem-c89","c89:-Ww -D__TANDEM -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1 -D_TANDEM_SOURCE -DB_ENDIAN::(unknown):::THIRTY_TWO_BIT:::",
18 +"uClinux-dist","$ENV{'CC'}:\$(CFLAGS)::-D_REENTRANT::\$(LDFLAGS) \$(LDLIBS):BN_LLONG::::::::::::\$(LIBSSL_dlfcn):linux-shared:-fPIC:-shared:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):$ENV{'RANLIB'}",
22 my @MK1MF_Builds=qw(VC-WIN64I VC-WIN64A
27 +my $have_cryptodev=0;
28 +my $use_cryptodev_digests=0;
30 my $Makefile="Makefile";
31 my $des_locl="crypto/des/des_locl.h";
36 + elsif (/^--with-cryptodev$/)
38 + $have_cryptodev = 1;
40 + elsif (/^--with-cryptodev-digests$/)
42 + $use_cryptodev_digests = 1;
44 elsif (/^reconfigure/ || /^reconf/)
46 if (open(IN,"<$Makefile"))
48 print " OPENSSL_NO_$ALGO";
50 if (/^err$/) { $flags .= "-DOPENSSL_NO_ERR "; }
51 + elsif (/^hw$/) { $flags .= "-DOPENSSL_NO_HW "; }
52 elsif (/^asm$/) { $no_asm = 1; }
55 @@ -1062,6 +1078,16 @@
56 $withargs{"krb5-dir"} ne "";
59 +# enable the linux cryptodev (ocf-linux) support
62 + if ($use_cryptodev_digests)
64 + $cflags = "-DUSE_CRYPTODEV_DIGESTS $cflags";
66 + $cflags = "-DHAVE_CRYPTODEV $cflags";
69 # The DSO code currently always implements all functions so that no
70 # applications will have to worry about that from a compilation point
71 # of view. However, the "method"s may return zero unless that platform
72 diff -Nur openssl-0.9.8h/INSTALL openssl-0.9.8h-ocf/INSTALL
73 --- openssl-0.9.8h/INSTALL 2008-04-07 08:35:41.000000000 +0200
74 +++ openssl-0.9.8h-ocf/INSTALL 2008-07-12 04:18:53.000000000 +0200
76 define preprocessor symbols, specify additional libraries,
77 library directories or other compiler options.
79 + --with-cryptodev Enabled the BSD cryptodev engine even if we are not using
80 + BSD. Useful if you are running ocf-linux or something
81 + similar. Once enabled you can also enable the use of
82 + cryptodev digests, with is usually slower unless you have
83 + large amounts data. Use --with-cryptodev-digests to force
86 Installation in Detail
87 ----------------------
88 diff -Nur openssl-0.9.8h/Makefile.org openssl-0.9.8h-ocf/Makefile.org
89 --- openssl-0.9.8h/Makefile.org 2008-04-04 01:03:39.000000000 +0200
90 +++ openssl-0.9.8h-ocf/Makefile.org 2008-07-12 04:18:53.000000000 +0200
94 @$(PERL) $(TOP)/util/mkdir-p.pl include/openssl
95 - @$(PERL) $(TOP)/util/mklink.pl include/openssl $(EXHEADER)
96 + @$(PERL) $(TOP)/util/mklink.pl include/openssl $(HEADER) $(EXHEADER)
97 @set -e; target=links; $(RECURSIVE_BUILD_CMD)
100 diff -Nur openssl-0.9.8h/Makefile.shared openssl-0.9.8h-ocf/Makefile.shared
101 --- openssl-0.9.8h/Makefile.shared 2007-09-16 16:11:51.000000000 +0200
102 +++ openssl-0.9.8h-ocf/Makefile.shared 2008-07-12 04:18:53.000000000 +0200
106 # CC contains the current compiler. This one MUST be defined
111 # LDFLAGS contains flags to be used when temporary object files (when building
112 # shared libraries) are created, or when an application is linked.
113 # SHARED_LDFLAGS contains flags to be used when the shared library is created.
119 # LIBNAME contains just the name of the library, without prefix ("lib"
120 # on Unix, "cyg" for certain forms under Cygwin...) or suffix (.a, .so,
121 diff -Nur openssl-0.9.8h/apps/apps.h openssl-0.9.8h-ocf/apps/apps.h
122 --- openssl-0.9.8h/apps/apps.h 2007-10-12 02:00:10.000000000 +0200
123 +++ openssl-0.9.8h-ocf/apps/apps.h 2008-07-12 04:18:53.000000000 +0200
125 #ifndef HEADER_APPS_H
126 #define HEADER_APPS_H
129 +#include <openssl/e_os.h>
131 #include <openssl/bio.h>
132 #include <openssl/x509.h>
133 diff -Nur openssl-0.9.8h/apps/progs.h openssl-0.9.8h-ocf/apps/progs.h
134 --- openssl-0.9.8h/apps/progs.h 2008-04-04 01:03:41.000000000 +0200
135 +++ openssl-0.9.8h-ocf/apps/progs.h 2008-07-12 04:18:53.000000000 +0200
137 #ifndef OPENSSL_NO_ENGINE
138 {FUNC_TYPE_GENERAL,"engine",engine_main},
140 +#ifndef OPENSSL_NO_OCSP
141 {FUNC_TYPE_GENERAL,"ocsp",ocsp_main},
143 {FUNC_TYPE_GENERAL,"prime",prime_main},
144 #ifndef OPENSSL_NO_MD2
145 {FUNC_TYPE_MD,"md2",dgst_main},
146 diff -Nur openssl-0.9.8h/apps/speed.c openssl-0.9.8h-ocf/apps/speed.c
147 --- openssl-0.9.8h/apps/speed.c 2007-11-15 14:33:47.000000000 +0100
148 +++ openssl-0.9.8h-ocf/apps/speed.c 2008-07-12 04:18:53.000000000 +0200
150 "evp","sha256","sha512",
151 "aes-128 ige","aes-192 ige","aes-256 ige"};
152 static double results[ALGOR_NUM][SIZE_NUM];
153 -static int lengths[SIZE_NUM]={16,64,256,1024,8*1024};
154 +static int lengths[SIZE_NUM]={16,64,256,1024,2*1024,4*1024};
155 static double rsa_results[RSA_NUM][2];
156 static double dsa_results[DSA_NUM][2];
157 #ifndef OPENSSL_NO_ECDSA
164 + * record CPU usage as well
167 +static int do_cpu = 0;
172 + unsigned int system;
174 + unsigned int total;
177 +static unsigned int cpu_usage[ALGOR_NUM][SIZE_NUM];
178 +static unsigned int rsa_cpu_usage[RSA_NUM][2];
179 +static unsigned int dsa_cpu_usage[DSA_NUM][2];
180 +static struct cpu_stat cpu_start, cpu_finish;
186 + unsigned char buf[80];
187 + struct cpu_stat *st = s == START ? &cpu_start : &cpu_finish;
189 + memset(st, 0, sizeof(*st));
192 + fp = fopen("/proc/stat", "r");
195 + if (fseek(fp, 0, SEEK_SET) == -1) {
199 + fscanf(fp, "%s %d %d %d %d", &buf[0], &st->user, &st->nice,
200 + &st->system, &st->idle);
201 + st->total = st->user + st->nice + st->system + st->idle;
208 + unsigned int total, res;
210 + total = cpu_finish.total - cpu_start.total;
214 + res = ((cpu_finish.system + cpu_finish.user + cpu_finish.nice) -
215 + (cpu_start.system + cpu_start.user + cpu_start.nice)) *
219 + res = (cpu_finish.system - cpu_start.system) * 100 / total;
222 + res = (cpu_finish.user - cpu_start.user) * 100 / total;
225 + res = (cpu_finish.nice - cpu_start.nice) * 100 / total;
228 + res = (cpu_finish.idle - cpu_start.idle) * 100 / total;
235 #if defined(OPENSSL_SYS_NETWARE)
237 /* for NetWare the best we can do is use clock() which returns the
251 j--; /* Otherwise, -elapsed gets confused with
255 + else if ((argc > 0) && (strcmp(*argv,"-cpu") == 0))
258 + j--; /* Otherwise, -cpu gets confused with
262 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
265 @@ -1260,6 +1346,9 @@
267 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
270 + BIO_printf(bio_err,"-cpu calculate cpu utilisation.\n");
275 @@ -1267,11 +1356,6 @@
280 - if(multi && do_multi(multi))
286 for (i=0; i<ALGOR_NUM; i++)
287 @@ -1604,6 +1688,11 @@
288 signal(SIGALRM,sig_done);
291 +#ifdef HAVE_FORK /* DM */
292 + if(multi && do_multi(multi))
296 #ifndef OPENSSL_NO_MD2
299 @@ -2033,8 +2122,6 @@
300 /* -O3 -fschedule-insns messes up an
301 * optimization here! names[D_EVP]
302 * somehow becomes NULL */
303 - print_message(names[D_EVP],save_count,
306 EVP_CIPHER_CTX_init(&ctx);
308 @@ -2043,6 +2130,9 @@
309 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
310 EVP_CIPHER_CTX_set_padding(&ctx, 0);
312 + print_message(names[D_EVP],save_count,
317 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
318 @@ -2107,6 +2197,8 @@
323 + rsa_cpu_usage[j][0] = calc_cpu();
324 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
325 : "%ld %d bit private RSA's in %.2fs\n",
326 count,rsa_bits[j],d);
327 @@ -2142,6 +2234,8 @@
332 + rsa_cpu_usage[j][1] = calc_cpu();
333 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
334 : "%ld %d bit public RSA's in %.2fs\n",
335 count,rsa_bits[j],d);
336 @@ -2201,6 +2295,8 @@
341 + dsa_cpu_usage[j][0] = calc_cpu();
342 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
343 : "%ld %d bit DSA signs in %.2fs\n",
344 count,dsa_bits[j],d);
345 @@ -2236,6 +2332,8 @@
350 + dsa_cpu_usage[j][1] = calc_cpu();
351 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
352 : "%ld %d bit DSA verify in %.2fs\n",
353 count,dsa_bits[j],d);
354 @@ -2530,14 +2628,23 @@
355 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
356 fprintf(stdout,"type ");
358 - for (j=0; j<SIZE_NUM; j++)
359 + for (j=0; j<SIZE_NUM; j++) {
360 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
362 + fprintf(stdout, " /cpu");
364 fprintf(stdout,"\n");
367 for (k=0; k<ALGOR_NUM; k++)
369 if (!doit[k]) continue;
372 + names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
374 + names[D_EVP]=OBJ_nid2ln(evp_md->type);
377 fprintf(stdout,"+F:%d:%s",k,names[k]);
379 @@ -2548,6 +2655,8 @@
380 fprintf(stdout," %11.2fk",results[k][j]/1e3);
382 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
384 + fprintf(stdout, mr ? "/%d" : "/%%%-3d", cpu_usage[k][j]);
386 fprintf(stdout,"\n");
388 @@ -2562,13 +2671,18 @@
392 - fprintf(stdout,"+F2:%u:%u:%f:%f\n",
393 - k,rsa_bits[k],rsa_results[k][0],
394 - rsa_results[k][1]);
396 - fprintf(stdout,"rsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
397 - rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
398 - 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
399 + fprintf(stdout,"+F2:%u:%u:%f", k,rsa_bits[k],rsa_results[k][0]);
401 + fprintf(stdout,"rsa %4u bits %8.6fs",rsa_bits[k],rsa_results[k][0]);
403 + fprintf(stdout, mr ? "/%d": "/%%%-3d", rsa_cpu_usage[k][0]);
404 + fprintf(stdout, mr ? ":%f" : " %8.6fs", rsa_results[k][1]);
406 + fprintf(stdout, mr ? "/%d": "/%%%-3d", rsa_cpu_usage[k][1]);
408 + fprintf(stdout, " %8.1f %8.1f",
409 + 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
410 + fprintf(stdout, "\n");
413 #ifndef OPENSSL_NO_DSA
414 @@ -2582,12 +2696,18 @@
418 - fprintf(stdout,"+F3:%u:%u:%f:%f\n",
419 - k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
420 + fprintf(stdout,"+F3:%u:%u:%f", k,dsa_bits[k],dsa_results[k][0]);
422 - fprintf(stdout,"dsa %4u bits %8.6fs %8.6fs %8.1f %8.1f\n",
423 - dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
424 - 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
425 + fprintf(stdout,"dsa %4u bits %8.6fs",dsa_bits[k],dsa_results[k][0]);
427 + fprintf(stdout, mr ? "/%d": "/%%%-3d", dsa_cpu_usage[k][0]);
428 + fprintf(stdout, mr ? ":%f" : " %8.6fs", dsa_results[k][1]);
430 + fprintf(stdout, mr ? "/%d": "/%%%-3d", dsa_cpu_usage[k][1]);
432 + fprintf(stdout, " %8.1f %8.1f",
433 + 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
434 + fprintf(stdout, "\n");
437 #ifndef OPENSSL_NO_ECDSA
438 @@ -2712,8 +2832,10 @@
440 static void print_result(int alg,int run_no,int count,double time_used)
442 - BIO_printf(bio_err,mr ? "+R:%d:%s:%f\n"
443 - : "%d %s's in %.2fs\n",count,names[alg],time_used);
445 + cpu_usage[alg][run_no] = calc_cpu();
446 + BIO_printf(bio_err,mr ? "+R:%ld:%s:%f\n"
447 + : "%ld %s's in %.2fs\n",count,names[alg],time_used);
448 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
451 @@ -2806,29 +2928,11 @@
453 alg=atoi(sstrsep(&p,sep));
455 - for(j=0 ; j < SIZE_NUM ; ++j)
456 + for(j=0 ; j < SIZE_NUM ; ++j) {
457 + if (do_cpu && strchr(p, '/'))
458 + cpu_usage[alg][j] = atoi(strchr(p, '/') + 1);
459 results[alg][j]+=atof(sstrsep(&p,sep));
461 - else if(!strncmp(buf,"+F2:",4))
467 - k=atoi(sstrsep(&p,sep));
470 - d=atof(sstrsep(&p,sep));
472 - rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
474 - rsa_results[k][0]=d;
476 - d=atof(sstrsep(&p,sep));
478 - rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
480 - rsa_results[k][1]=d;
482 else if(!strncmp(buf,"+F2:",4))
484 @@ -2839,12 +2943,18 @@
485 k=atoi(sstrsep(&p,sep));
488 + /* before we move the token along */
489 + if (do_cpu && strchr(p, '/'))
490 + rsa_cpu_usage[k][0] = atoi(strchr(p, '/') + 1);
491 d=atof(sstrsep(&p,sep));
493 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
497 + /* before we move the token along */
498 + if (do_cpu && strchr(p, '/'))
499 + rsa_cpu_usage[k][1] = atoi(strchr(p, '/') + 1);
500 d=atof(sstrsep(&p,sep));
502 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
503 @@ -2860,12 +2970,18 @@
504 k=atoi(sstrsep(&p,sep));
507 + /* before we move the token along */
508 + if (do_cpu && strchr(p, '/'))
509 + dsa_cpu_usage[k][0] = atoi(strchr(p, '/') + 1);
510 d=atof(sstrsep(&p,sep));
512 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
516 + /* before we move the token along */
517 + if (do_cpu && strchr(p, '/'))
518 + dsa_cpu_usage[k][1] = atoi(strchr(p, '/') + 1);
519 d=atof(sstrsep(&p,sep));
521 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
522 diff -Nur openssl-0.9.8h/config openssl-0.9.8h-ocf/config
523 --- openssl-0.9.8h/config 2007-08-01 13:21:35.000000000 +0200
524 +++ openssl-0.9.8h-ocf/config 2008-07-12 04:18:53.000000000 +0200
527 # First get uname entries that we use below
529 -MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown"
530 -RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
531 -SYSTEM=`(uname -s) 2>/dev/null` || SYSTEM="unknown"
532 -VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown"
533 +[ "$MACHINE" ] || MACHINE=`(uname -m) 2>/dev/null` || MACHINE="unknown"
534 +[ "$RELEASE" ] || RELEASE=`(uname -r) 2>/dev/null` || RELEASE="unknown"
535 +[ "$SYSTEM" ] || SYSTEM=`(uname -s) 2>/dev/null` || SYSTEM="unknown"
536 +[ "$VERSION" ] || VERSION=`(uname -v) 2>/dev/null` || VERSION="unknown"
539 # Now test for ISC and SCO, since it is has a braindamaged uname.
541 echo "ppc-apple-darwin${VERSION}"
544 - echo "i386-apple-darwin${VERSION}"
545 + echo "${MACHINE}-apple-darwin${VERSION}"
551 # figure out if gcc is available and if so we use it otherwise
552 # we fallback to whatever cc does on the system
553 -GCCVER=`(gcc -dumpversion) 2>/dev/null`
555 +GCCVER=`(${CC} -dumpversion) 2>/dev/null`
556 if [ "$GCCVER" != "" ]; then
558 # then strip off whatever prefix egcs prepends the number with...
559 # Hopefully, this will work for any future prefixes as well.
560 GCCVER=`echo $GCCVER | LC_ALL=C sed 's/^[a-zA-Z]*\-//'`
562 # peak single digit before and after first dot, e.g. 2.95.1 gives 29
563 GCCVER=`echo $GCCVER | sed 's/\([0-9]\)\.\([0-9]\).*/\1\2/'`
569 if [ "$SYSTEM" = "HP-UX" ];then
571 # script above so we end up with values in vars but that would take
572 # more time that I want to waste at the moment
578 CPU=`(hinv -t cpu) 2>/dev/null | head -1 | sed 's/^CPU:[^R]*R\([0-9]*\).*/\1/'`
580 diff -Nur openssl-0.9.8h/crypto/cryptlib.h openssl-0.9.8h-ocf/crypto/cryptlib.h
581 --- openssl-0.9.8h/crypto/cryptlib.h 2005-05-21 15:19:44.000000000 +0200
582 +++ openssl-0.9.8h-ocf/crypto/cryptlib.h 2008-07-12 04:18:53.000000000 +0200
588 +#include <openssl/e_os.h>
590 #ifdef OPENSSL_USE_APPLINK
591 #define BIO_FLAGS_UPLINK 0x8000
592 diff -Nur openssl-0.9.8h/crypto/engine/eng_all.c openssl-0.9.8h-ocf/crypto/engine/eng_all.c
593 --- openssl-0.9.8h/crypto/engine/eng_all.c 2007-01-04 23:55:25.000000000 +0100
594 +++ openssl-0.9.8h-ocf/crypto/engine/eng_all.c 2008-07-12 04:18:53.000000000 +0200
595 @@ -104,13 +104,13 @@
598 #ifndef OPENSSL_NO_HW
599 -#if defined(__OpenBSD__) || defined(__FreeBSD__)
600 +#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
601 ENGINE_load_cryptodev();
606 -#if defined(__OpenBSD__) || defined(__FreeBSD__)
607 +#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
608 void ENGINE_setup_bsd_cryptodev(void) {
609 static int bsd_cryptodev_default_loaded = 0;
610 if (!bsd_cryptodev_default_loaded) {
611 diff -Nur openssl-0.9.8h/crypto/engine/eng_cryptodev.c openssl-0.9.8h-ocf/crypto/engine/eng_cryptodev.c
612 --- openssl-0.9.8h/crypto/engine/eng_cryptodev.c 2004-06-15 13:45:42.000000000 +0200
613 +++ openssl-0.9.8h-ocf/crypto/engine/eng_cryptodev.c 2008-07-12 04:18:53.000000000 +0200
615 struct dev_crypto_state {
616 struct session_op d_sess;
619 +#ifdef USE_CRYPTODEV_DIGESTS
620 + char dummy_mac_key[20];
622 + unsigned char digest_res[20];
630 static u_int32_t cryptodev_asymfeat = 0;
632 static int get_asym_dev_crypto(void);
633 static int open_dev_crypto(void);
634 static int get_dev_crypto(void);
636 static int cryptodev_max_iv(int cipher);
637 static int cryptodev_key_length_valid(int cipher, int len);
638 static int cipher_nid_to_cryptodev(int nid);
640 static int get_cryptodev_ciphers(const int **cnids);
641 static int get_cryptodev_digests(const int **cnids);
642 static int cryptodev_usable_ciphers(const int **nids);
644 static int cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a,
645 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
646 static int cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I,
648 + RSA *rsa, BN_CTX *ctx);
649 static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
650 static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a,
651 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
653 { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, },
654 { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, },
655 { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, },
656 + { CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, },
657 { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, },
658 { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, },
659 { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, },
660 @@ -142,14 +155,15 @@
666 - { CRYPTO_SHA1_HMAC, NID_hmacWithSHA1, },
667 - { CRYPTO_RIPEMD160_HMAC, NID_ripemd160, },
668 - { CRYPTO_MD5_KPDK, NID_undef, },
669 - { CRYPTO_SHA1_KPDK, NID_undef, },
670 - { CRYPTO_MD5, NID_md5, },
671 - { CRYPTO_SHA1, NID_undef, },
673 + { CRYPTO_SHA1_HMAC, NID_hmacWithSHA1, 20},
674 + { CRYPTO_RIPEMD160_HMAC, NID_ripemd160, 16/*?*/},
675 + { CRYPTO_MD5_KPDK, NID_undef, 0},
676 + { CRYPTO_SHA1_KPDK, NID_undef, 0},
677 + { CRYPTO_MD5, NID_md5, 16},
678 + { CRYPTO_SHA1, NID_sha1, 20},
679 + { 0, NID_undef, 0},
683 @@ -176,10 +190,17 @@
688 + static int fd = -1;
691 - if ((fd = open_dev_crypto()) == -1)
694 + if ((fd = open_dev_crypto()) == -1)
696 + if (fcntl(fd, F_SETFD, 1) == -1) {
701 if (ioctl(fd, CRIOGET, &retfd) == -1)
710 * XXXX this needs to be set for each alg - and determined from
713 return (ciphers[i].id);
719 * Find out what ciphers /dev/crypto will let us have a session for.
723 memset(&sess, 0, sizeof(sess));
724 - sess.key = (caddr_t)"123456781234567812345678";
725 + sess.key = (caddr_t)"123456789abcdefghijklmno";
727 for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
728 if (ciphers[i].nid == NID_undef)
729 @@ -303,10 +326,12 @@
732 memset(&sess, 0, sizeof(sess));
733 + sess.mackey = (caddr_t)"123456789abcdefghijklmno";
734 for (i = 0; digests[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
735 if (digests[i].nid == NID_undef)
737 sess.mac = digests[i].id;
738 + sess.mackeylen = digests[i].keylen;
740 if (ioctl(fd, CIOCGSESSION, &sess) != -1 &&
741 ioctl(fd, CIOCFSESSION, &sess.ses) != -1)
744 cryptodev_usable_digests(const int **nids)
746 +#ifdef USE_CRYPTODEV_DIGESTS
747 + return (get_cryptodev_digests(nids));
750 * XXXX just disable all digests for now, because it sucks.
751 * we need a better way to decide this - i.e. I may not
760 @@ -427,16 +456,20 @@
762 struct dev_crypto_state *state = ctx->cipher_data;
763 struct session_op *sess = &state->d_sess;
766 - if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NID_undef)
770 - if (ctx->cipher->iv_len > cryptodev_max_iv(cipher))
772 + for (i = 0; ciphers[i].id; i++)
773 + if (ctx->cipher->nid == ciphers[i].nid &&
774 + ctx->cipher->iv_len <= ciphers[i].ivmax &&
775 + ctx->key_len == ciphers[i].keylen) {
776 + cipher = ciphers[i].id;
780 - if (!cryptodev_key_length_valid(cipher, ctx->key_len))
781 + if (!ciphers[i].id) {
786 memset(sess, 0, sizeof(struct session_op));
792 +const EVP_CIPHER cryptodev_aes_256_cbc = {
796 + cryptodev_init_key,
799 + sizeof(struct dev_crypto_state),
800 + EVP_CIPHER_set_asn1_iv,
801 + EVP_CIPHER_get_asn1_iv,
806 * Registered by the ENGINE when used to find out how to deal with
807 * a particular NID in the ENGINE. this says what we'll do at the
809 case NID_aes_128_cbc:
810 *cipher = &cryptodev_aes_cbc;
812 + case NID_aes_256_cbc:
813 + *cipher = &cryptodev_aes_256_cbc;
818 @@ -598,6 +647,234 @@
819 return (*cipher != NULL);
823 +#ifdef USE_CRYPTODEV_DIGESTS
825 +/* convert digest type to cryptodev */
827 +digest_nid_to_cryptodev(int nid)
831 + for (i = 0; digests[i].id; i++)
832 + if (digests[i].nid == nid)
833 + return (digests[i].id);
839 +digest_key_length(int nid)
843 + for (i = 0; digests[i].id; i++)
844 + if (digests[i].nid == nid)
845 + return digests[i].keylen;
850 +static int cryptodev_digest_init(EVP_MD_CTX *ctx)
852 + struct dev_crypto_state *state = ctx->md_data;
853 + struct session_op *sess = &state->d_sess;
856 + if ((digest = digest_nid_to_cryptodev(ctx->digest->type)) == NID_undef){
857 + printf("cryptodev_digest_init: Can't get digest \n");
861 + memset(state, 0, sizeof(struct dev_crypto_state));
863 + if ((state->d_fd = get_dev_crypto()) < 0) {
864 + printf("cryptodev_digest_init: Can't get Dev \n");
868 + sess->mackey = state->dummy_mac_key;
869 + sess->mackeylen = digest_key_length(ctx->digest->type);
870 + sess->mac = digest;
872 + if (ioctl(state->d_fd, CIOCGSESSION, sess) < 0) {
873 + close(state->d_fd);
875 + printf("cryptodev_digest_init: Open session failed\n");
882 +static int cryptodev_digest_update(EVP_MD_CTX *ctx, const void *data,
885 + struct crypt_op cryp;
886 + struct dev_crypto_state *state = ctx->md_data;
887 + struct session_op *sess = &state->d_sess;
889 + if (!data || state->d_fd < 0) {
890 + printf("cryptodev_digest_update: illegal inputs \n");
898 + if (!(ctx->flags & EVP_MD_CTX_FLAG_ONESHOT)) {
899 + /* if application doesn't support one buffer */
900 + state->mac_data = OPENSSL_realloc(state->mac_data, state->mac_len + count);
902 + if (!state->mac_data) {
903 + printf("cryptodev_digest_update: realloc failed\n");
907 + memcpy(state->mac_data + state->mac_len, data, count);
908 + state->mac_len += count;
913 + memset(&cryp, 0, sizeof(cryp));
915 + cryp.ses = sess->ses;
918 + cryp.src = (caddr_t) data;
920 + cryp.mac = state->digest_res;
921 + if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) {
922 + printf("cryptodev_digest_update: digest failed\n");
929 +static int cryptodev_digest_final(EVP_MD_CTX *ctx, unsigned char *md)
931 + struct crypt_op cryp;
932 + struct dev_crypto_state *state = ctx->md_data;
933 + struct session_op *sess = &state->d_sess;
937 + if (!md || state->d_fd < 0) {
938 + printf("cryptodev_digest_final: illegal input\n");
942 + if (! (ctx->flags & EVP_MD_CTX_FLAG_ONESHOT) ) {
943 + /* if application doesn't support one buffer */
944 + memset(&cryp, 0, sizeof(cryp));
946 + cryp.ses = sess->ses;
948 + cryp.len = state->mac_len;
949 + cryp.src = state->mac_data;
953 + if (ioctl(state->d_fd, CIOCCRYPT, &cryp) < 0) {
954 + printf("cryptodev_digest_final: digest failed\n");
961 + memcpy(md, state->digest_res, ctx->digest->md_size);
967 +static int cryptodev_digest_cleanup(EVP_MD_CTX *ctx)
970 + struct dev_crypto_state *state = ctx->md_data;
971 + struct session_op *sess = &state->d_sess;
973 + if (state->d_fd < 0) {
974 + printf("cryptodev_digest_cleanup: illegal input\n");
978 + if (state->mac_data) {
979 + OPENSSL_free(state->mac_data);
980 + state->mac_data = NULL;
981 + state->mac_len = 0;
987 + if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) < 0) {
988 + printf("cryptodev_digest_cleanup: failed to close session\n");
993 + close(state->d_fd);
999 +static int cryptodev_digest_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
1001 + struct dev_crypto_state *fstate = from->md_data;
1002 + struct dev_crypto_state *dstate = to->md_data;
1004 + memcpy(dstate, fstate, sizeof(struct dev_crypto_state));
1006 + if (fstate->mac_len != 0) {
1007 + dstate->mac_data = OPENSSL_malloc(fstate->mac_len);
1008 + memcpy(dstate->mac_data, fstate->mac_data, fstate->mac_len);
1017 +const EVP_MD cryptodev_sha1 = {
1020 + SHA_DIGEST_LENGTH,
1021 + EVP_MD_FLAG_ONESHOT,
1022 + cryptodev_digest_init,
1023 + cryptodev_digest_update,
1024 + cryptodev_digest_final,
1025 + cryptodev_digest_copy,
1026 + cryptodev_digest_cleanup,
1027 + EVP_PKEY_NULL_method,
1029 + sizeof(struct dev_crypto_state),
1032 +const EVP_MD cryptodev_md5 = {
1035 + 16 /* MD5_DIGEST_LENGTH */,
1036 + EVP_MD_FLAG_ONESHOT,
1037 + cryptodev_digest_init,
1038 + cryptodev_digest_update,
1039 + cryptodev_digest_final,
1040 + cryptodev_digest_copy,
1041 + cryptodev_digest_cleanup,
1042 + EVP_PKEY_NULL_method,
1043 + 64 /* MD5_CBLOCK */,
1044 + sizeof(struct dev_crypto_state),
1047 +#endif /* USE_CRYPTODEV_DIGESTS */
1051 cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
1052 const int **nids, int nid)
1053 @@ -606,10 +883,15 @@
1054 return (cryptodev_usable_digests(nids));
1057 +#ifdef USE_CRYPTODEV_DIGESTS
1059 - *digest = NULL; /* need to make a clean md5 critter */
1060 + *digest = &cryptodev_md5;
1063 + *digest = &cryptodev_sha1;
1066 +#endif /* USE_CRYPTODEV_DIGESTS */
1071 bn2crparam(const BIGNUM *a, struct crparam *crp)
1074 - ssize_t words, bytes, bits;
1075 + ssize_t bytes, bits;
1083 + memset(b, 0, bytes);
1086 crp->crp_nbits = bits;
1091 - for (i = 0; i <= kop->crk_iparams + kop->crk_oparams; i++) {
1092 + for (i = 0; i < kop->crk_iparams + kop->crk_oparams; i++) {
1093 if (kop->crk_param[i].crp_p)
1094 free(kop->crk_param[i].crp_p);
1095 kop->crk_param[i].crp_p = NULL;
1096 @@ -756,12 +1039,10 @@
1100 -cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
1101 +cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
1106 - ctx = BN_CTX_new();
1107 + ctx = BN_CTX_new(); /* not sure why we reallocate this. DM */
1108 r = cryptodev_bn_mod_exp(r0, I, rsa->d, rsa->n, ctx, NULL);
1111 diff -Nur openssl-0.9.8h/crypto/engine/eng_table.c openssl-0.9.8h-ocf/crypto/engine/eng_table.c
1112 --- openssl-0.9.8h/crypto/engine/eng_table.c 2008-04-28 23:45:43.000000000 +0200
1113 +++ openssl-0.9.8h-ocf/crypto/engine/eng_table.c 2008-07-12 04:18:53.000000000 +0200
1116 engine_unlocked_finish(e, 0);
1118 + /* "touch" this ENGINE_CIPHER */
1119 + pile->uptodate = 0;
1122 static IMPLEMENT_LHASH_DOALL_ARG_FN(int_unregister_cb,ENGINE_PILE *,ENGINE *)
1123 diff -Nur openssl-0.9.8h/crypto/engine/engine.h openssl-0.9.8h-ocf/crypto/engine/engine.h
1124 --- openssl-0.9.8h/crypto/engine/engine.h 2005-11-06 18:48:59.000000000 +0100
1125 +++ openssl-0.9.8h-ocf/crypto/engine/engine.h 2008-07-12 04:18:53.000000000 +0200
1128 void *ENGINE_get_static_state(void);
1130 -#if defined(__OpenBSD__) || defined(__FreeBSD__)
1131 +#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
1132 void ENGINE_setup_bsd_cryptodev(void);
1135 diff -Nur openssl-0.9.8h/crypto/evp/c_all.c openssl-0.9.8h-ocf/crypto/evp/c_all.c
1136 --- openssl-0.9.8h/crypto/evp/c_all.c 2004-08-29 18:36:04.000000000 +0200
1137 +++ openssl-0.9.8h-ocf/crypto/evp/c_all.c 2008-07-12 04:18:53.000000000 +0200
1139 OpenSSL_add_all_ciphers();
1140 OpenSSL_add_all_digests();
1141 #ifndef OPENSSL_NO_ENGINE
1142 -# if defined(__OpenBSD__) || defined(__FreeBSD__)
1143 +# if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
1144 ENGINE_setup_bsd_cryptodev();
1147 diff -Nur openssl-0.9.8h/crypto/evp/c_alld.c openssl-0.9.8h-ocf/crypto/evp/c_alld.c
1148 --- openssl-0.9.8h/crypto/evp/c_alld.c 2005-04-30 23:51:40.000000000 +0200
1149 +++ openssl-0.9.8h-ocf/crypto/evp/c_alld.c 2008-07-12 04:18:53.000000000 +0200
1151 EVP_add_digest(EVP_dss());
1154 -#ifndef OPENSSL_NO_SHA
1155 +#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1)
1156 EVP_add_digest(EVP_sha1());
1157 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
1158 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
1159 diff -Nur openssl-0.9.8h/engines/Makefile openssl-0.9.8h-ocf/engines/Makefile
1160 --- openssl-0.9.8h/engines/Makefile 2006-02-04 02:49:34.000000000 +0100
1161 +++ openssl-0.9.8h-ocf/engines/Makefile 2008-07-12 04:18:53.000000000 +0200
1163 ( echo installing $$l; \
1164 if [ "$(PLATFORM)" != "Cygwin" ]; then \
1165 case "$(CFLAGS)" in \
1166 + *OPENSSL_NO_HW*) continue;; \
1167 *DSO_DLFCN*) sfx="so";; \
1168 *DSO_DL*) sfx="sl";; \
1170 diff -Nur openssl-0.9.8h/util/domd openssl-0.9.8h-ocf/util/domd
1171 --- openssl-0.9.8h/util/domd 2005-03-30 16:44:50.000000000 +0200
1172 +++ openssl-0.9.8h-ocf/util/domd 2008-07-12 04:18:53.000000000 +0200
1175 sed -e '/^# DO NOT DELETE.*/,$d' < Makefile > Makefile.tmp
1176 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' >> Makefile.tmp
1177 - ${MAKEDEPEND} -D OPENSSL_DOING_MAKEDEPEND -M $args >> Makefile.tmp
1178 + ${MAKEDEPEND} -D OPENSSL_DOING_MAKEDEPEND -M $args >> Makefile.tmp &&
1179 ${PERL} $TOP/util/clean-depend.pl < Makefile.tmp > Makefile.new
1183 - ${MAKEDEPEND} -D OPENSSL_DOING_MAKEDEPEND $@
1184 + ${MAKEDEPEND} -D OPENSSL_DOING_MAKEDEPEND $@ && \
1185 ${PERL} $TOP/util/clean-depend.pl < Makefile > Makefile.new
1188 mv Makefile.new Makefile
1189 # unfake the presence of Kerberos