diff options
| author | ryker <> | 1998-10-05 20:13:14 +0000 |
|---|---|---|
| committer | ryker <> | 1998-10-05 20:13:14 +0000 |
| commit | fe5d0717e2760d02faf23bf5a714f17b33ae4abb (patch) | |
| tree | 8d4ad346f10a36bdd90b503d222bda6b4ecd0037 /src/lib/libcrypto/des | |
| parent | 75bf5ead4149b2b67781def7ace1ec720ae1753e (diff) | |
| parent | aeeae06a79815dc190061534d47236cec09f9e32 (diff) | |
| download | openbsd-fe5d0717e2760d02faf23bf5a714f17b33ae4abb.tar.gz openbsd-fe5d0717e2760d02faf23bf5a714f17b33ae4abb.tar.bz2 openbsd-fe5d0717e2760d02faf23bf5a714f17b33ae4abb.zip | |
This commit was generated by cvs2git to track changes on a CVS vendor
branch.
Diffstat (limited to 'src/lib/libcrypto/des')
27 files changed, 4393 insertions, 0 deletions
diff --git a/src/lib/libcrypto/des/COPYRIGHT b/src/lib/libcrypto/des/COPYRIGHT new file mode 100644 index 0000000000..5469e1e469 --- /dev/null +++ b/src/lib/libcrypto/des/COPYRIGHT | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | ||
| 2 | All rights reserved. | ||
| 3 | |||
| 4 | This package is an DES implementation written by Eric Young (eay@cryptsoft.com). | ||
| 5 | The implementation was written so as to conform with MIT's libdes. | ||
| 6 | |||
| 7 | This library is free for commercial and non-commercial use as long as | ||
| 8 | the following conditions are aheared to. The following conditions | ||
| 9 | apply to all code found in this distribution. | ||
| 10 | |||
| 11 | Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 12 | the code are not to be removed. | ||
| 13 | If this package is used in a product, Eric Young should be given attribution | ||
| 14 | as the author of that the SSL library. This can be in the form of a textual | ||
| 15 | message at program startup or in documentation (online or textual) provided | ||
| 16 | with the package. | ||
| 17 | |||
| 18 | Redistribution and use in source and binary forms, with or without | ||
| 19 | modification, are permitted provided that the following conditions | ||
| 20 | are met: | ||
| 21 | 1. Redistributions of source code must retain the copyright | ||
| 22 | notice, this list of conditions and the following disclaimer. | ||
| 23 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 24 | notice, this list of conditions and the following disclaimer in the | ||
| 25 | documentation and/or other materials provided with the distribution. | ||
| 26 | 3. All advertising materials mentioning features or use of this software | ||
| 27 | must display the following acknowledgement: | ||
| 28 | This product includes software developed by Eric Young (eay@cryptsoft.com) | ||
| 29 | |||
| 30 | THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 31 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 32 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 33 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 34 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 35 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 36 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 37 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 38 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 39 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 40 | SUCH DAMAGE. | ||
| 41 | |||
| 42 | The license and distribution terms for any publically available version or | ||
| 43 | derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 44 | copied and put under another distrubution license | ||
| 45 | [including the GNU Public License.] | ||
| 46 | |||
| 47 | The reason behind this being stated in this direct manner is past | ||
| 48 | experience in code simply being copied and the attribution removed | ||
| 49 | from it and then being distributed as part of other packages. This | ||
| 50 | implementation was a non-trivial and unpaid effort. | ||
diff --git a/src/lib/libcrypto/des/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl new file mode 100644 index 0000000000..297e38dec8 --- /dev/null +++ b/src/lib/libcrypto/des/asm/crypt586.pl | |||
| @@ -0,0 +1,204 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | # | ||
| 3 | # The inner loop instruction sequence and the IP/FP modifications are from | ||
| 4 | # Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> | ||
| 5 | # I've added the stuff needed for crypt() but I've not worried about making | ||
| 6 | # things perfect. | ||
| 7 | # | ||
| 8 | |||
| 9 | push(@INC,"perlasm","../../perlasm"); | ||
| 10 | require "x86asm.pl"; | ||
| 11 | |||
| 12 | &asm_init($ARGV[0],"crypt586.pl"); | ||
| 13 | |||
| 14 | $L="edi"; | ||
| 15 | $R="esi"; | ||
| 16 | |||
| 17 | &external_label("des_SPtrans"); | ||
| 18 | &fcrypt_body("fcrypt_body"); | ||
| 19 | &asm_finish(); | ||
| 20 | |||
| 21 | sub fcrypt_body | ||
| 22 | { | ||
| 23 | local($name,$do_ip)=@_; | ||
| 24 | |||
| 25 | &function_begin($name,"EXTRN _des_SPtrans:DWORD"); | ||
| 26 | |||
| 27 | &comment(""); | ||
| 28 | &comment("Load the 2 words"); | ||
| 29 | $ks="ebp"; | ||
| 30 | |||
| 31 | &xor( $L, $L); | ||
| 32 | &xor( $R, $R); | ||
| 33 | &mov($ks,&wparam(1)); | ||
| 34 | |||
| 35 | &push(25); # add a variable | ||
| 36 | |||
| 37 | &set_label("start"); | ||
| 38 | for ($i=0; $i<16; $i+=2) | ||
| 39 | { | ||
| 40 | &comment(""); | ||
| 41 | &comment("Round $i"); | ||
| 42 | &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 43 | |||
| 44 | &comment(""); | ||
| 45 | &comment("Round ".sprintf("%d",$i+1)); | ||
| 46 | &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 47 | } | ||
| 48 | &mov("ebx", &swtmp(0)); | ||
| 49 | &mov("eax", $L); | ||
| 50 | &dec("ebx"); | ||
| 51 | &mov($L, $R); | ||
| 52 | &mov($R, "eax"); | ||
| 53 | &mov(&swtmp(0), "ebx"); | ||
| 54 | &jnz(&label("start")); | ||
| 55 | |||
| 56 | &comment(""); | ||
| 57 | &comment("FP"); | ||
| 58 | &mov("edx",&wparam(0)); | ||
| 59 | |||
| 60 | &FP_new($R,$L,"eax",3); | ||
| 61 | &mov(&DWP(0,"edx","",0),"eax"); | ||
| 62 | &mov(&DWP(4,"edx","",0),$L); | ||
| 63 | |||
| 64 | &pop("ecx"); # remove variable | ||
| 65 | |||
| 66 | &function_end($name); | ||
| 67 | } | ||
| 68 | |||
| 69 | sub D_ENCRYPT | ||
| 70 | { | ||
| 71 | local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_; | ||
| 72 | |||
| 73 | &mov( $u, &wparam(2)); # 2 | ||
| 74 | &mov( $t, $R); | ||
| 75 | &shr( $t, 16); # 1 | ||
| 76 | &mov( $tmp2, &wparam(3)); # 2 | ||
| 77 | &xor( $t, $R); # 1 | ||
| 78 | |||
| 79 | &and( $u, $t); # 2 | ||
| 80 | &and( $t, $tmp2); # 2 | ||
| 81 | |||
| 82 | &mov( $tmp1, $u); | ||
| 83 | &shl( $tmp1, 16); # 1 | ||
| 84 | &mov( $tmp2, $t); | ||
| 85 | &shl( $tmp2, 16); # 1 | ||
| 86 | &xor( $u, $tmp1); # 2 | ||
| 87 | &xor( $t, $tmp2); # 2 | ||
| 88 | &mov( $tmp1, &DWP(&n2a($S*4),$ks,"",0)); # 2 | ||
| 89 | &xor( $u, $tmp1); | ||
| 90 | &mov( $tmp2, &DWP(&n2a(($S+1)*4),$ks,"",0)); # 2 | ||
| 91 | &xor( $u, $R); | ||
| 92 | &xor( $t, $R); | ||
| 93 | &xor( $t, $tmp2); | ||
| 94 | |||
| 95 | &and( $u, "0xfcfcfcfc" ); # 2 | ||
| 96 | &xor( $tmp1, $tmp1); # 1 | ||
| 97 | &and( $t, "0xcfcfcfcf" ); # 2 | ||
| 98 | &xor( $tmp2, $tmp2); | ||
| 99 | &movb( &LB($tmp1), &LB($u) ); | ||
| 100 | &movb( &LB($tmp2), &HB($u) ); | ||
| 101 | &rotr( $t, 4 ); | ||
| 102 | &mov( $ks, &DWP(" $desSP",$tmp1,"",0)); | ||
| 103 | &movb( &LB($tmp1), &LB($t) ); | ||
| 104 | &xor( $L, $ks); | ||
| 105 | &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0)); | ||
| 106 | &xor( $L, $ks); | ||
| 107 | &movb( &LB($tmp2), &HB($t) ); | ||
| 108 | &shr( $u, 16); | ||
| 109 | &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0)); | ||
| 110 | &xor( $L, $ks); | ||
| 111 | &movb( &LB($tmp1), &HB($u) ); | ||
| 112 | &shr( $t, 16); | ||
| 113 | &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0)); | ||
| 114 | &xor( $L, $ks); | ||
| 115 | &mov( $ks, &wparam(1)); | ||
| 116 | &movb( &LB($tmp2), &HB($t) ); | ||
| 117 | &and( $u, "0xff" ); | ||
| 118 | &and( $t, "0xff" ); | ||
| 119 | &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0)); | ||
| 120 | &xor( $L, $tmp1); | ||
| 121 | &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0)); | ||
| 122 | &xor( $L, $tmp1); | ||
| 123 | &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0)); | ||
| 124 | &xor( $L, $tmp1); | ||
| 125 | &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0)); | ||
| 126 | &xor( $L, $tmp1); | ||
| 127 | } | ||
| 128 | |||
| 129 | sub n2a | ||
| 130 | { | ||
| 131 | sprintf("%d",$_[0]); | ||
| 132 | } | ||
| 133 | |||
| 134 | # now has a side affect of rotating $a by $shift | ||
| 135 | sub R_PERM_OP | ||
| 136 | { | ||
| 137 | local($a,$b,$tt,$shift,$mask,$last)=@_; | ||
| 138 | |||
| 139 | &rotl( $a, $shift ) if ($shift != 0); | ||
| 140 | &mov( $tt, $a ); | ||
| 141 | &xor( $a, $b ); | ||
| 142 | &and( $a, $mask ); | ||
| 143 | if ($notlast eq $b) | ||
| 144 | { | ||
| 145 | &xor( $b, $a ); | ||
| 146 | &xor( $tt, $a ); | ||
| 147 | } | ||
| 148 | else | ||
| 149 | { | ||
| 150 | &xor( $tt, $a ); | ||
| 151 | &xor( $b, $a ); | ||
| 152 | } | ||
| 153 | &comment(""); | ||
| 154 | } | ||
| 155 | |||
| 156 | sub IP_new | ||
| 157 | { | ||
| 158 | local($l,$r,$tt,$lr)=@_; | ||
| 159 | |||
| 160 | &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l); | ||
| 161 | &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l); | ||
| 162 | &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r); | ||
| 163 | &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r); | ||
| 164 | &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r); | ||
| 165 | |||
| 166 | if ($lr != 3) | ||
| 167 | { | ||
| 168 | if (($lr-3) < 0) | ||
| 169 | { &rotr($tt, 3-$lr); } | ||
| 170 | else { &rotl($tt, $lr-3); } | ||
| 171 | } | ||
| 172 | if ($lr != 2) | ||
| 173 | { | ||
| 174 | if (($lr-2) < 0) | ||
| 175 | { &rotr($r, 2-$lr); } | ||
| 176 | else { &rotl($r, $lr-2); } | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | sub FP_new | ||
| 181 | { | ||
| 182 | local($l,$r,$tt,$lr)=@_; | ||
| 183 | |||
| 184 | if ($lr != 2) | ||
| 185 | { | ||
| 186 | if (($lr-2) < 0) | ||
| 187 | { &rotl($r, 2-$lr); } | ||
| 188 | else { &rotr($r, $lr-2); } | ||
| 189 | } | ||
| 190 | if ($lr != 3) | ||
| 191 | { | ||
| 192 | if (($lr-3) < 0) | ||
| 193 | { &rotl($l, 3-$lr); } | ||
| 194 | else { &rotr($l, $lr-3); } | ||
| 195 | } | ||
| 196 | |||
| 197 | &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r); | ||
| 198 | &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r); | ||
| 199 | &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l); | ||
| 200 | &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l); | ||
| 201 | &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r); | ||
| 202 | &rotr($tt , 4); | ||
| 203 | } | ||
| 204 | |||
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl new file mode 100644 index 0000000000..7f2e09fa7a --- /dev/null +++ b/src/lib/libcrypto/des/asm/des-586.pl | |||
| @@ -0,0 +1,251 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | # | ||
| 3 | # The inner loop instruction sequence and the IP/FP modifications are from | ||
| 4 | # Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> | ||
| 5 | # | ||
| 6 | |||
| 7 | push(@INC,"perlasm","../../perlasm"); | ||
| 8 | require "x86asm.pl"; | ||
| 9 | require "cbc.pl"; | ||
| 10 | require "desboth.pl"; | ||
| 11 | |||
| 12 | # base code is in microsft | ||
| 13 | # op dest, source | ||
| 14 | # format. | ||
| 15 | # | ||
| 16 | |||
| 17 | &asm_init($ARGV[0],"des-586.pl"); | ||
| 18 | |||
| 19 | $L="edi"; | ||
| 20 | $R="esi"; | ||
| 21 | |||
| 22 | &external_label("des_SPtrans"); | ||
| 23 | &des_encrypt("des_encrypt",1); | ||
| 24 | &des_encrypt("des_encrypt2",0); | ||
| 25 | &des_encrypt3("des_encrypt3",1); | ||
| 26 | &des_encrypt3("des_decrypt3",0); | ||
| 27 | &cbc("des_ncbc_encrypt","des_encrypt","des_encrypt",0,4,5,3,5,-1); | ||
| 28 | &cbc("des_ede3_cbc_encrypt","des_encrypt3","des_decrypt3",0,6,7,3,4,5); | ||
| 29 | |||
| 30 | &asm_finish(); | ||
| 31 | |||
| 32 | sub des_encrypt | ||
| 33 | { | ||
| 34 | local($name,$do_ip)=@_; | ||
| 35 | |||
| 36 | &function_begin_B($name,"EXTRN _des_SPtrans:DWORD"); | ||
| 37 | |||
| 38 | &push("esi"); | ||
| 39 | &push("edi"); | ||
| 40 | |||
| 41 | &comment(""); | ||
| 42 | &comment("Load the 2 words"); | ||
| 43 | $ks="ebp"; | ||
| 44 | |||
| 45 | if ($do_ip) | ||
| 46 | { | ||
| 47 | &mov($R,&wparam(0)); | ||
| 48 | &xor( "ecx", "ecx" ); | ||
| 49 | |||
| 50 | &push("ebx"); | ||
| 51 | &push("ebp"); | ||
| 52 | |||
| 53 | &mov("eax",&DWP(0,$R,"",0)); | ||
| 54 | &mov("ebx",&wparam(2)); # get encrypt flag | ||
| 55 | &mov($L,&DWP(4,$R,"",0)); | ||
| 56 | &comment(""); | ||
| 57 | &comment("IP"); | ||
| 58 | &IP_new("eax",$L,$R,3); | ||
| 59 | } | ||
| 60 | else | ||
| 61 | { | ||
| 62 | &mov("eax",&wparam(0)); | ||
| 63 | &xor( "ecx", "ecx" ); | ||
| 64 | |||
| 65 | &push("ebx"); | ||
| 66 | &push("ebp"); | ||
| 67 | |||
| 68 | &mov($R,&DWP(0,"eax","",0)); | ||
| 69 | &mov("ebx",&wparam(2)); # get encrypt flag | ||
| 70 | &rotl($R,3); | ||
| 71 | &mov($L,&DWP(4,"eax","",0)); | ||
| 72 | &rotl($L,3); | ||
| 73 | } | ||
| 74 | |||
| 75 | &mov( $ks, &wparam(1) ); | ||
| 76 | &cmp("ebx","0"); | ||
| 77 | &je(&label("start_decrypt")); | ||
| 78 | |||
| 79 | for ($i=0; $i<16; $i+=2) | ||
| 80 | { | ||
| 81 | &comment(""); | ||
| 82 | &comment("Round $i"); | ||
| 83 | &D_ENCRYPT($i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 84 | |||
| 85 | &comment(""); | ||
| 86 | &comment("Round ".sprintf("%d",$i+1)); | ||
| 87 | &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 88 | } | ||
| 89 | &jmp(&label("end")); | ||
| 90 | |||
| 91 | &set_label("start_decrypt"); | ||
| 92 | |||
| 93 | for ($i=15; $i>0; $i-=2) | ||
| 94 | { | ||
| 95 | &comment(""); | ||
| 96 | &comment("Round $i"); | ||
| 97 | &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 98 | &comment(""); | ||
| 99 | &comment("Round ".sprintf("%d",$i-1)); | ||
| 100 | &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"des_SPtrans","eax","ebx","ecx","edx"); | ||
| 101 | } | ||
| 102 | |||
| 103 | &set_label("end"); | ||
| 104 | |||
| 105 | if ($do_ip) | ||
| 106 | { | ||
| 107 | &comment(""); | ||
| 108 | &comment("FP"); | ||
| 109 | &mov("edx",&wparam(0)); | ||
| 110 | &FP_new($L,$R,"eax",3); | ||
| 111 | |||
| 112 | &mov(&DWP(0,"edx","",0),"eax"); | ||
| 113 | &mov(&DWP(4,"edx","",0),$R); | ||
| 114 | } | ||
| 115 | else | ||
| 116 | { | ||
| 117 | &comment(""); | ||
| 118 | &comment("Fixup"); | ||
| 119 | &rotr($L,3); # r | ||
| 120 | &mov("eax",&wparam(0)); | ||
| 121 | &rotr($R,3); # l | ||
| 122 | &mov(&DWP(0,"eax","",0),$L); | ||
| 123 | &mov(&DWP(4,"eax","",0),$R); | ||
| 124 | } | ||
| 125 | |||
| 126 | &pop("ebp"); | ||
| 127 | &pop("ebx"); | ||
| 128 | &pop("edi"); | ||
| 129 | &pop("esi"); | ||
| 130 | &ret(); | ||
| 131 | |||
| 132 | &function_end_B($name); | ||
| 133 | } | ||
| 134 | |||
| 135 | sub D_ENCRYPT | ||
| 136 | { | ||
| 137 | local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_; | ||
| 138 | |||
| 139 | &mov( $u, &DWP(&n2a($S*4),$ks,"",0)); | ||
| 140 | &xor( $tmp1, $tmp1); | ||
| 141 | &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0)); | ||
| 142 | &xor( $u, $R); | ||
| 143 | &xor( $t, $R); | ||
| 144 | &and( $u, "0xfcfcfcfc" ); | ||
| 145 | &and( $t, "0xcfcfcfcf" ); | ||
| 146 | &movb( &LB($tmp1), &LB($u) ); | ||
| 147 | &movb( &LB($tmp2), &HB($u) ); | ||
| 148 | &rotr( $t, 4 ); | ||
| 149 | &mov( $ks, &DWP(" $desSP",$tmp1,"",0)); | ||
| 150 | &movb( &LB($tmp1), &LB($t) ); | ||
| 151 | &xor( $L, $ks); | ||
| 152 | &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0)); | ||
| 153 | &xor( $L, $ks); ###### | ||
| 154 | &movb( &LB($tmp2), &HB($t) ); | ||
| 155 | &shr( $u, 16); | ||
| 156 | &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0)); | ||
| 157 | &xor( $L, $ks); ###### | ||
| 158 | &movb( &LB($tmp1), &HB($u) ); | ||
| 159 | &shr( $t, 16); | ||
| 160 | &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0)); | ||
| 161 | &xor( $L, $ks); | ||
| 162 | &mov( $ks, &wparam(1) ); | ||
| 163 | &movb( &LB($tmp2), &HB($t) ); | ||
| 164 | &and( $u, "0xff" ); | ||
| 165 | &and( $t, "0xff" ); | ||
| 166 | &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0)); | ||
| 167 | &xor( $L, $tmp1); | ||
| 168 | &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0)); | ||
| 169 | &xor( $L, $tmp1); | ||
| 170 | &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0)); | ||
| 171 | &xor( $L, $tmp1); | ||
| 172 | &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0)); | ||
| 173 | &xor( $L, $tmp1); | ||
| 174 | } | ||
| 175 | |||
| 176 | sub n2a | ||
| 177 | { | ||
| 178 | sprintf("%d",$_[0]); | ||
| 179 | } | ||
| 180 | |||
| 181 | # now has a side affect of rotating $a by $shift | ||
| 182 | sub R_PERM_OP | ||
| 183 | { | ||
| 184 | local($a,$b,$tt,$shift,$mask,$last)=@_; | ||
| 185 | |||
| 186 | &rotl( $a, $shift ) if ($shift != 0); | ||
| 187 | &mov( $tt, $a ); | ||
| 188 | &xor( $a, $b ); | ||
| 189 | &and( $a, $mask ); | ||
| 190 | if (!$last eq $b) | ||
| 191 | { | ||
| 192 | &xor( $b, $a ); | ||
| 193 | &xor( $tt, $a ); | ||
| 194 | } | ||
| 195 | else | ||
| 196 | { | ||
| 197 | &xor( $tt, $a ); | ||
| 198 | &xor( $b, $a ); | ||
| 199 | } | ||
| 200 | &comment(""); | ||
| 201 | } | ||
| 202 | |||
| 203 | sub IP_new | ||
| 204 | { | ||
| 205 | local($l,$r,$tt,$lr)=@_; | ||
| 206 | |||
| 207 | &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l); | ||
| 208 | &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l); | ||
| 209 | &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r); | ||
| 210 | &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r); | ||
| 211 | &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r); | ||
| 212 | |||
| 213 | if ($lr != 3) | ||
| 214 | { | ||
| 215 | if (($lr-3) < 0) | ||
| 216 | { &rotr($tt, 3-$lr); } | ||
| 217 | else { &rotl($tt, $lr-3); } | ||
| 218 | } | ||
| 219 | if ($lr != 2) | ||
| 220 | { | ||
| 221 | if (($lr-2) < 0) | ||
| 222 | { &rotr($r, 2-$lr); } | ||
| 223 | else { &rotl($r, $lr-2); } | ||
| 224 | } | ||
| 225 | } | ||
| 226 | |||
| 227 | sub FP_new | ||
| 228 | { | ||
| 229 | local($l,$r,$tt,$lr)=@_; | ||
| 230 | |||
| 231 | if ($lr != 2) | ||
| 232 | { | ||
| 233 | if (($lr-2) < 0) | ||
| 234 | { &rotl($r, 2-$lr); } | ||
| 235 | else { &rotr($r, $lr-2); } | ||
| 236 | } | ||
| 237 | if ($lr != 3) | ||
| 238 | { | ||
| 239 | if (($lr-3) < 0) | ||
| 240 | { &rotl($l, 3-$lr); } | ||
| 241 | else { &rotr($l, $lr-3); } | ||
| 242 | } | ||
| 243 | |||
| 244 | &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r); | ||
| 245 | &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r); | ||
| 246 | &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l); | ||
| 247 | &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l); | ||
| 248 | &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r); | ||
| 249 | &rotr($tt , 4); | ||
| 250 | } | ||
| 251 | |||
diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl new file mode 100644 index 0000000000..8f939953a6 --- /dev/null +++ b/src/lib/libcrypto/des/asm/desboth.pl | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | $L="edi"; | ||
| 4 | $R="esi"; | ||
| 5 | |||
| 6 | sub des_encrypt3 | ||
| 7 | { | ||
| 8 | local($name,$enc)=@_; | ||
| 9 | |||
| 10 | &function_begin_B($name,""); | ||
| 11 | &push("ebx"); | ||
| 12 | &mov("ebx",&wparam(0)); | ||
| 13 | |||
| 14 | &push("ebp"); | ||
| 15 | &push("esi"); | ||
| 16 | |||
| 17 | &push("edi"); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &comment("Load the data words"); | ||
| 21 | &mov($L,&DWP(0,"ebx","",0)); | ||
| 22 | &mov($R,&DWP(4,"ebx","",0)); | ||
| 23 | &stack_push(3); | ||
| 24 | |||
| 25 | &comment(""); | ||
| 26 | &comment("IP"); | ||
| 27 | &IP_new($L,$R,"edx",0); | ||
| 28 | |||
| 29 | # put them back | ||
| 30 | |||
| 31 | if ($enc) | ||
| 32 | { | ||
| 33 | &mov(&DWP(4,"ebx","",0),$R); | ||
| 34 | &mov("eax",&wparam(1)); | ||
| 35 | &mov(&DWP(0,"ebx","",0),"edx"); | ||
| 36 | &mov("edi",&wparam(2)); | ||
| 37 | &mov("esi",&wparam(3)); | ||
| 38 | } | ||
| 39 | else | ||
| 40 | { | ||
| 41 | &mov(&DWP(4,"ebx","",0),$R); | ||
| 42 | &mov("esi",&wparam(1)); | ||
| 43 | &mov(&DWP(0,"ebx","",0),"edx"); | ||
| 44 | &mov("edi",&wparam(2)); | ||
| 45 | &mov("eax",&wparam(3)); | ||
| 46 | } | ||
| 47 | &mov(&swtmp(2), (($enc)?"1":"0")); | ||
| 48 | &mov(&swtmp(1), "eax"); | ||
| 49 | &mov(&swtmp(0), "ebx"); | ||
| 50 | &call("des_encrypt2"); | ||
| 51 | &mov(&swtmp(2), (($enc)?"0":"1")); | ||
| 52 | &mov(&swtmp(1), "edi"); | ||
| 53 | &mov(&swtmp(0), "ebx"); | ||
| 54 | &call("des_encrypt2"); | ||
| 55 | &mov(&swtmp(2), (($enc)?"1":"0")); | ||
| 56 | &mov(&swtmp(1), "esi"); | ||
| 57 | &mov(&swtmp(0), "ebx"); | ||
| 58 | &call("des_encrypt2"); | ||
| 59 | |||
| 60 | &stack_pop(3); | ||
| 61 | &mov($L,&DWP(0,"ebx","",0)); | ||
| 62 | &mov($R,&DWP(4,"ebx","",0)); | ||
| 63 | |||
| 64 | &comment(""); | ||
| 65 | &comment("FP"); | ||
| 66 | &FP_new($L,$R,"eax",0); | ||
| 67 | |||
| 68 | &mov(&DWP(0,"ebx","",0),"eax"); | ||
| 69 | &mov(&DWP(4,"ebx","",0),$R); | ||
| 70 | |||
| 71 | &pop("edi"); | ||
| 72 | &pop("esi"); | ||
| 73 | &pop("ebp"); | ||
| 74 | &pop("ebx"); | ||
| 75 | &ret(); | ||
| 76 | &function_end_B($name); | ||
| 77 | } | ||
| 78 | |||
| 79 | |||
diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c new file mode 100644 index 0000000000..edfdec8a0f --- /dev/null +++ b/src/lib/libcrypto/des/cbc_cksm.c | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | /* crypto/des/cbc_cksm.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | DES_LONG des_cbc_cksum(input, output, length, schedule, ivec) | ||
| 62 | des_cblock (*input); | ||
| 63 | des_cblock (*output); | ||
| 64 | long length; | ||
| 65 | des_key_schedule schedule; | ||
| 66 | des_cblock (*ivec); | ||
| 67 | { | ||
| 68 | register DES_LONG tout0,tout1,tin0,tin1; | ||
| 69 | register long l=length; | ||
| 70 | DES_LONG tin[2]; | ||
| 71 | unsigned char *in,*out,*iv; | ||
| 72 | |||
| 73 | in=(unsigned char *)input; | ||
| 74 | out=(unsigned char *)output; | ||
| 75 | iv=(unsigned char *)ivec; | ||
| 76 | |||
| 77 | c2l(iv,tout0); | ||
| 78 | c2l(iv,tout1); | ||
| 79 | for (; l>0; l-=8) | ||
| 80 | { | ||
| 81 | if (l >= 8) | ||
| 82 | { | ||
| 83 | c2l(in,tin0); | ||
| 84 | c2l(in,tin1); | ||
| 85 | } | ||
| 86 | else | ||
| 87 | c2ln(in,tin0,tin1,l); | ||
| 88 | |||
| 89 | tin0^=tout0; tin[0]=tin0; | ||
| 90 | tin1^=tout1; tin[1]=tin1; | ||
| 91 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 92 | /* fix 15/10/91 eay - thanks to keithr@sco.COM */ | ||
| 93 | tout0=tin[0]; | ||
| 94 | tout1=tin[1]; | ||
| 95 | } | ||
| 96 | if (out != NULL) | ||
| 97 | { | ||
| 98 | l2c(tout0,out); | ||
| 99 | l2c(tout1,out); | ||
| 100 | } | ||
| 101 | tout0=tin0=tin1=tin[0]=tin[1]=0; | ||
| 102 | return(tout1); | ||
| 103 | } | ||
diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c new file mode 100644 index 0000000000..a84a53633c --- /dev/null +++ b/src/lib/libcrypto/des/cbc_enc.c | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | /* crypto/des/cbc_enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | void des_cbc_encrypt(input, output, length, schedule, ivec, enc) | ||
| 62 | des_cblock (*input); | ||
| 63 | des_cblock (*output); | ||
| 64 | long length; | ||
| 65 | des_key_schedule schedule; | ||
| 66 | des_cblock (*ivec); | ||
| 67 | int enc; | ||
| 68 | { | ||
| 69 | register DES_LONG tin0,tin1; | ||
| 70 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 71 | register unsigned char *in,*out; | ||
| 72 | register long l=length; | ||
| 73 | DES_LONG tin[2]; | ||
| 74 | unsigned char *iv; | ||
| 75 | |||
| 76 | in=(unsigned char *)input; | ||
| 77 | out=(unsigned char *)output; | ||
| 78 | iv=(unsigned char *)ivec; | ||
| 79 | |||
| 80 | if (enc) | ||
| 81 | { | ||
| 82 | c2l(iv,tout0); | ||
| 83 | c2l(iv,tout1); | ||
| 84 | for (l-=8; l>=0; l-=8) | ||
| 85 | { | ||
| 86 | c2l(in,tin0); | ||
| 87 | c2l(in,tin1); | ||
| 88 | tin0^=tout0; tin[0]=tin0; | ||
| 89 | tin1^=tout1; tin[1]=tin1; | ||
| 90 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 91 | tout0=tin[0]; l2c(tout0,out); | ||
| 92 | tout1=tin[1]; l2c(tout1,out); | ||
| 93 | } | ||
| 94 | if (l != -8) | ||
| 95 | { | ||
| 96 | c2ln(in,tin0,tin1,l+8); | ||
| 97 | tin0^=tout0; tin[0]=tin0; | ||
| 98 | tin1^=tout1; tin[1]=tin1; | ||
| 99 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 100 | tout0=tin[0]; l2c(tout0,out); | ||
| 101 | tout1=tin[1]; l2c(tout1,out); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | else | ||
| 105 | { | ||
| 106 | c2l(iv,xor0); | ||
| 107 | c2l(iv,xor1); | ||
| 108 | for (l-=8; l>=0; l-=8) | ||
| 109 | { | ||
| 110 | c2l(in,tin0); tin[0]=tin0; | ||
| 111 | c2l(in,tin1); tin[1]=tin1; | ||
| 112 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 113 | tout0=tin[0]^xor0; | ||
| 114 | tout1=tin[1]^xor1; | ||
| 115 | l2c(tout0,out); | ||
| 116 | l2c(tout1,out); | ||
| 117 | xor0=tin0; | ||
| 118 | xor1=tin1; | ||
| 119 | } | ||
| 120 | if (l != -8) | ||
| 121 | { | ||
| 122 | c2l(in,tin0); tin[0]=tin0; | ||
| 123 | c2l(in,tin1); tin[1]=tin1; | ||
| 124 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 125 | tout0=tin[0]^xor0; | ||
| 126 | tout1=tin[1]^xor1; | ||
| 127 | l2cn(tout0,tout1,out,l+8); | ||
| 128 | /* xor0=tin0; | ||
| 129 | xor1=tin1; */ | ||
| 130 | } | ||
| 131 | } | ||
| 132 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 133 | tin[0]=tin[1]=0; | ||
| 134 | } | ||
| 135 | |||
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c new file mode 100644 index 0000000000..80b8a9eaaa --- /dev/null +++ b/src/lib/libcrypto/des/cfb64ede.c | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | /* crypto/des/cfb64ede.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit cfb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | |||
| 66 | void des_ede3_cfb64_encrypt(in, out, length, ks1,ks2,ks3, ivec, num, enc) | ||
| 67 | unsigned char *in; | ||
| 68 | unsigned char *out; | ||
| 69 | long length; | ||
| 70 | des_key_schedule ks1,ks2,ks3; | ||
| 71 | des_cblock (*ivec); | ||
| 72 | int *num; | ||
| 73 | int enc; | ||
| 74 | { | ||
| 75 | register DES_LONG v0,v1; | ||
| 76 | register long l=length; | ||
| 77 | register int n= *num; | ||
| 78 | DES_LONG ti[2]; | ||
| 79 | unsigned char *iv,c,cc; | ||
| 80 | |||
| 81 | iv=(unsigned char *)ivec; | ||
| 82 | if (enc) | ||
| 83 | { | ||
| 84 | while (l--) | ||
| 85 | { | ||
| 86 | if (n == 0) | ||
| 87 | { | ||
| 88 | c2l(iv,v0); | ||
| 89 | c2l(iv,v1); | ||
| 90 | |||
| 91 | ti[0]=v0; | ||
| 92 | ti[1]=v1; | ||
| 93 | des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); | ||
| 94 | v0=ti[0]; | ||
| 95 | v1=ti[1]; | ||
| 96 | |||
| 97 | iv=(unsigned char *)ivec; | ||
| 98 | l2c(v0,iv); | ||
| 99 | l2c(v1,iv); | ||
| 100 | iv=(unsigned char *)ivec; | ||
| 101 | } | ||
| 102 | c= *(in++)^iv[n]; | ||
| 103 | *(out++)=c; | ||
| 104 | iv[n]=c; | ||
| 105 | n=(n+1)&0x07; | ||
| 106 | } | ||
| 107 | } | ||
| 108 | else | ||
| 109 | { | ||
| 110 | while (l--) | ||
| 111 | { | ||
| 112 | if (n == 0) | ||
| 113 | { | ||
| 114 | c2l(iv,v0); | ||
| 115 | c2l(iv,v1); | ||
| 116 | |||
| 117 | ti[0]=v0; | ||
| 118 | ti[1]=v1; | ||
| 119 | des_encrypt3((DES_LONG *)ti,ks1,ks2,ks3); | ||
| 120 | v0=ti[0]; | ||
| 121 | v1=ti[1]; | ||
| 122 | |||
| 123 | iv=(unsigned char *)ivec; | ||
| 124 | l2c(v0,iv); | ||
| 125 | l2c(v1,iv); | ||
| 126 | iv=(unsigned char *)ivec; | ||
| 127 | } | ||
| 128 | cc= *(in++); | ||
| 129 | c=iv[n]; | ||
| 130 | iv[n]=cc; | ||
| 131 | *(out++)=c^cc; | ||
| 132 | n=(n+1)&0x07; | ||
| 133 | } | ||
| 134 | } | ||
| 135 | v0=v1=ti[0]=ti[1]=c=cc=0; | ||
| 136 | *num=n; | ||
| 137 | } | ||
| 138 | |||
| 139 | #ifdef undef /* MACRO */ | ||
| 140 | void des_ede2_cfb64_encrypt(in, out, length, ks1,ks2, ivec, num, enc) | ||
| 141 | unsigned char *in; | ||
| 142 | unsigned char *out; | ||
| 143 | long length; | ||
| 144 | des_key_schedule ks1,ks2; | ||
| 145 | des_cblock (*ivec); | ||
| 146 | int *num; | ||
| 147 | int enc; | ||
| 148 | { | ||
| 149 | des_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc); | ||
| 150 | } | ||
| 151 | #endif | ||
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c new file mode 100644 index 0000000000..403da479df --- /dev/null +++ b/src/lib/libcrypto/des/cfb64enc.c | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | /* crypto/des/cfb64enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit cfb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | |||
| 66 | void des_cfb64_encrypt(in, out, length, schedule, ivec, num, enc) | ||
| 67 | unsigned char *in; | ||
| 68 | unsigned char *out; | ||
| 69 | long length; | ||
| 70 | des_key_schedule schedule; | ||
| 71 | des_cblock (*ivec); | ||
| 72 | int *num; | ||
| 73 | int enc; | ||
| 74 | { | ||
| 75 | register DES_LONG v0,v1; | ||
| 76 | register long l=length; | ||
| 77 | register int n= *num; | ||
| 78 | DES_LONG ti[2]; | ||
| 79 | unsigned char *iv,c,cc; | ||
| 80 | |||
| 81 | iv=(unsigned char *)ivec; | ||
| 82 | if (enc) | ||
| 83 | { | ||
| 84 | while (l--) | ||
| 85 | { | ||
| 86 | if (n == 0) | ||
| 87 | { | ||
| 88 | c2l(iv,v0); ti[0]=v0; | ||
| 89 | c2l(iv,v1); ti[1]=v1; | ||
| 90 | des_encrypt((DES_LONG *)ti, | ||
| 91 | schedule,DES_ENCRYPT); | ||
| 92 | iv=(unsigned char *)ivec; | ||
| 93 | v0=ti[0]; l2c(v0,iv); | ||
| 94 | v0=ti[1]; l2c(v0,iv); | ||
| 95 | iv=(unsigned char *)ivec; | ||
| 96 | } | ||
| 97 | c= *(in++)^iv[n]; | ||
| 98 | *(out++)=c; | ||
| 99 | iv[n]=c; | ||
| 100 | n=(n+1)&0x07; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | else | ||
| 104 | { | ||
| 105 | while (l--) | ||
| 106 | { | ||
| 107 | if (n == 0) | ||
| 108 | { | ||
| 109 | c2l(iv,v0); ti[0]=v0; | ||
| 110 | c2l(iv,v1); ti[1]=v1; | ||
| 111 | des_encrypt((DES_LONG *)ti, | ||
| 112 | schedule,DES_ENCRYPT); | ||
| 113 | iv=(unsigned char *)ivec; | ||
| 114 | v0=ti[0]; l2c(v0,iv); | ||
| 115 | v0=ti[1]; l2c(v0,iv); | ||
| 116 | iv=(unsigned char *)ivec; | ||
| 117 | } | ||
| 118 | cc= *(in++); | ||
| 119 | c=iv[n]; | ||
| 120 | iv[n]=cc; | ||
| 121 | *(out++)=c^cc; | ||
| 122 | n=(n+1)&0x07; | ||
| 123 | } | ||
| 124 | } | ||
| 125 | v0=v1=ti[0]=ti[1]=c=cc=0; | ||
| 126 | *num=n; | ||
| 127 | } | ||
| 128 | |||
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c new file mode 100644 index 0000000000..342e785691 --- /dev/null +++ b/src/lib/libcrypto/des/cfb_enc.c | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | /* crypto/des/cfb_enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output are loaded in multiples of 8 bits. | ||
| 62 | * What this means is that if you hame numbits=12 and length=2 | ||
| 63 | * the first 12 bits will be retrieved from the first byte and half | ||
| 64 | * the second. The second 12 bits will come from the 3rd and half the 4th | ||
| 65 | * byte. | ||
| 66 | */ | ||
| 67 | void des_cfb_encrypt(in, out, numbits, length, schedule, ivec, enc) | ||
| 68 | unsigned char *in; | ||
| 69 | unsigned char *out; | ||
| 70 | int numbits; | ||
| 71 | long length; | ||
| 72 | des_key_schedule schedule; | ||
| 73 | des_cblock (*ivec); | ||
| 74 | int enc; | ||
| 75 | { | ||
| 76 | register DES_LONG d0,d1,v0,v1,n=(numbits+7)/8; | ||
| 77 | register DES_LONG mask0,mask1; | ||
| 78 | register unsigned long l=length; | ||
| 79 | register int num=numbits; | ||
| 80 | DES_LONG ti[2]; | ||
| 81 | unsigned char *iv; | ||
| 82 | |||
| 83 | if (num > 64) return; | ||
| 84 | if (num > 32) | ||
| 85 | { | ||
| 86 | mask0=0xffffffffL; | ||
| 87 | if (num == 64) | ||
| 88 | mask1=mask0; | ||
| 89 | else mask1=(1L<<(num-32))-1; | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | if (num == 32) | ||
| 94 | mask0=0xffffffffL; | ||
| 95 | else mask0=(1L<<num)-1; | ||
| 96 | mask1=0x00000000L; | ||
| 97 | } | ||
| 98 | |||
| 99 | iv=(unsigned char *)ivec; | ||
| 100 | c2l(iv,v0); | ||
| 101 | c2l(iv,v1); | ||
| 102 | if (enc) | ||
| 103 | { | ||
| 104 | while (l >= n) | ||
| 105 | { | ||
| 106 | l-=n; | ||
| 107 | ti[0]=v0; | ||
| 108 | ti[1]=v1; | ||
| 109 | des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 110 | c2ln(in,d0,d1,n); | ||
| 111 | in+=n; | ||
| 112 | d0=(d0^ti[0])&mask0; | ||
| 113 | d1=(d1^ti[1])&mask1; | ||
| 114 | l2cn(d0,d1,out,n); | ||
| 115 | out+=n; | ||
| 116 | /* 30-08-94 - eay - changed because l>>32 and | ||
| 117 | * l<<32 are bad under gcc :-( */ | ||
| 118 | if (num == 32) | ||
| 119 | { v0=v1; v1=d0; } | ||
| 120 | else if (num == 64) | ||
| 121 | { v0=d0; v1=d1; } | ||
| 122 | else if (num > 32) /* && num != 64 */ | ||
| 123 | { | ||
| 124 | v0=((v1>>(num-32))|(d0<<(64-num)))&0xffffffffL; | ||
| 125 | v1=((d0>>(num-32))|(d1<<(64-num)))&0xffffffffL; | ||
| 126 | } | ||
| 127 | else /* num < 32 */ | ||
| 128 | { | ||
| 129 | v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL; | ||
| 130 | v1=((v1>>num)|(d0<<(32-num)))&0xffffffffL; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
| 134 | else | ||
| 135 | { | ||
| 136 | while (l >= n) | ||
| 137 | { | ||
| 138 | l-=n; | ||
| 139 | ti[0]=v0; | ||
| 140 | ti[1]=v1; | ||
| 141 | des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 142 | c2ln(in,d0,d1,n); | ||
| 143 | in+=n; | ||
| 144 | /* 30-08-94 - eay - changed because l>>32 and | ||
| 145 | * l<<32 are bad under gcc :-( */ | ||
| 146 | if (num == 32) | ||
| 147 | { v0=v1; v1=d0; } | ||
| 148 | else if (num == 64) | ||
| 149 | { v0=d0; v1=d1; } | ||
| 150 | else if (num > 32) /* && num != 64 */ | ||
| 151 | { | ||
| 152 | v0=((v1>>(num-32))|(d0<<(64-num)))&0xffffffffL; | ||
| 153 | v1=((d0>>(num-32))|(d1<<(64-num)))&0xffffffffL; | ||
| 154 | } | ||
| 155 | else /* num < 32 */ | ||
| 156 | { | ||
| 157 | v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL; | ||
| 158 | v1=((v1>>num)|(d0<<(32-num)))&0xffffffffL; | ||
| 159 | } | ||
| 160 | d0=(d0^ti[0])&mask0; | ||
| 161 | d1=(d1^ti[1])&mask1; | ||
| 162 | l2cn(d0,d1,out,n); | ||
| 163 | out+=n; | ||
| 164 | } | ||
| 165 | } | ||
| 166 | iv=(unsigned char *)ivec; | ||
| 167 | l2c(v0,iv); | ||
| 168 | l2c(v1,iv); | ||
| 169 | v0=v1=d0=d1=ti[0]=ti[1]=0; | ||
| 170 | } | ||
| 171 | |||
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c new file mode 100644 index 0000000000..e4db09299e --- /dev/null +++ b/src/lib/libcrypto/des/des_enc.c | |||
| @@ -0,0 +1,502 @@ | |||
| 1 | /* crypto/des/des_enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | void des_encrypt(data, ks, enc) | ||
| 62 | DES_LONG *data; | ||
| 63 | des_key_schedule ks; | ||
| 64 | int enc; | ||
| 65 | { | ||
| 66 | register DES_LONG l,r,t,u; | ||
| 67 | #ifdef DES_PTR | ||
| 68 | register unsigned char *des_SP=(unsigned char *)des_SPtrans; | ||
| 69 | #endif | ||
| 70 | #ifndef DES_UNROLL | ||
| 71 | register int i; | ||
| 72 | #endif | ||
| 73 | register DES_LONG *s; | ||
| 74 | |||
| 75 | r=data[0]; | ||
| 76 | l=data[1]; | ||
| 77 | |||
| 78 | IP(r,l); | ||
| 79 | /* Things have been modified so that the initial rotate is | ||
| 80 | * done outside the loop. This required the | ||
| 81 | * des_SPtrans values in sp.h to be rotated 1 bit to the right. | ||
| 82 | * One perl script later and things have a 5% speed up on a sparc2. | ||
| 83 | * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> | ||
| 84 | * for pointing this out. */ | ||
| 85 | /* clear the top bits on machines with 8byte longs */ | ||
| 86 | /* shift left by 2 */ | ||
| 87 | r=ROTATE(r,29)&0xffffffffL; | ||
| 88 | l=ROTATE(l,29)&0xffffffffL; | ||
| 89 | |||
| 90 | s=(DES_LONG *)ks; | ||
| 91 | /* I don't know if it is worth the effort of loop unrolling the | ||
| 92 | * inner loop */ | ||
| 93 | if (enc) | ||
| 94 | { | ||
| 95 | #ifdef DES_UNROLL | ||
| 96 | D_ENCRYPT(l,r, 0); /* 1 */ | ||
| 97 | D_ENCRYPT(r,l, 2); /* 2 */ | ||
| 98 | D_ENCRYPT(l,r, 4); /* 3 */ | ||
| 99 | D_ENCRYPT(r,l, 6); /* 4 */ | ||
| 100 | D_ENCRYPT(l,r, 8); /* 5 */ | ||
| 101 | D_ENCRYPT(r,l,10); /* 6 */ | ||
| 102 | D_ENCRYPT(l,r,12); /* 7 */ | ||
| 103 | D_ENCRYPT(r,l,14); /* 8 */ | ||
| 104 | D_ENCRYPT(l,r,16); /* 9 */ | ||
| 105 | D_ENCRYPT(r,l,18); /* 10 */ | ||
| 106 | D_ENCRYPT(l,r,20); /* 11 */ | ||
| 107 | D_ENCRYPT(r,l,22); /* 12 */ | ||
| 108 | D_ENCRYPT(l,r,24); /* 13 */ | ||
| 109 | D_ENCRYPT(r,l,26); /* 14 */ | ||
| 110 | D_ENCRYPT(l,r,28); /* 15 */ | ||
| 111 | D_ENCRYPT(r,l,30); /* 16 */ | ||
| 112 | #else | ||
| 113 | for (i=0; i<32; i+=8) | ||
| 114 | { | ||
| 115 | D_ENCRYPT(l,r,i+0); /* 1 */ | ||
| 116 | D_ENCRYPT(r,l,i+2); /* 2 */ | ||
| 117 | D_ENCRYPT(l,r,i+4); /* 3 */ | ||
| 118 | D_ENCRYPT(r,l,i+6); /* 4 */ | ||
| 119 | } | ||
| 120 | #endif | ||
| 121 | } | ||
| 122 | else | ||
| 123 | { | ||
| 124 | #ifdef DES_UNROLL | ||
| 125 | D_ENCRYPT(l,r,30); /* 16 */ | ||
| 126 | D_ENCRYPT(r,l,28); /* 15 */ | ||
| 127 | D_ENCRYPT(l,r,26); /* 14 */ | ||
| 128 | D_ENCRYPT(r,l,24); /* 13 */ | ||
| 129 | D_ENCRYPT(l,r,22); /* 12 */ | ||
| 130 | D_ENCRYPT(r,l,20); /* 11 */ | ||
| 131 | D_ENCRYPT(l,r,18); /* 10 */ | ||
| 132 | D_ENCRYPT(r,l,16); /* 9 */ | ||
| 133 | D_ENCRYPT(l,r,14); /* 8 */ | ||
| 134 | D_ENCRYPT(r,l,12); /* 7 */ | ||
| 135 | D_ENCRYPT(l,r,10); /* 6 */ | ||
| 136 | D_ENCRYPT(r,l, 8); /* 5 */ | ||
| 137 | D_ENCRYPT(l,r, 6); /* 4 */ | ||
| 138 | D_ENCRYPT(r,l, 4); /* 3 */ | ||
| 139 | D_ENCRYPT(l,r, 2); /* 2 */ | ||
| 140 | D_ENCRYPT(r,l, 0); /* 1 */ | ||
| 141 | #else | ||
| 142 | for (i=30; i>0; i-=8) | ||
| 143 | { | ||
| 144 | D_ENCRYPT(l,r,i-0); /* 16 */ | ||
| 145 | D_ENCRYPT(r,l,i-2); /* 15 */ | ||
| 146 | D_ENCRYPT(l,r,i-4); /* 14 */ | ||
| 147 | D_ENCRYPT(r,l,i-6); /* 13 */ | ||
| 148 | } | ||
| 149 | #endif | ||
| 150 | } | ||
| 151 | |||
| 152 | /* rotate and clear the top bits on machines with 8byte longs */ | ||
| 153 | l=ROTATE(l,3)&0xffffffffL; | ||
| 154 | r=ROTATE(r,3)&0xffffffffL; | ||
| 155 | |||
| 156 | FP(r,l); | ||
| 157 | data[0]=l; | ||
| 158 | data[1]=r; | ||
| 159 | l=r=t=u=0; | ||
| 160 | } | ||
| 161 | |||
| 162 | void des_encrypt2(data, ks, enc) | ||
| 163 | DES_LONG *data; | ||
| 164 | des_key_schedule ks; | ||
| 165 | int enc; | ||
| 166 | { | ||
| 167 | register DES_LONG l,r,t,u; | ||
| 168 | #ifdef DES_PTR | ||
| 169 | register unsigned char *des_SP=(unsigned char *)des_SPtrans; | ||
| 170 | #endif | ||
| 171 | #ifndef DES_UNROLL | ||
| 172 | register int i; | ||
| 173 | #endif | ||
| 174 | register DES_LONG *s; | ||
| 175 | |||
| 176 | r=data[0]; | ||
| 177 | l=data[1]; | ||
| 178 | |||
| 179 | /* Things have been modified so that the initial rotate is | ||
| 180 | * done outside the loop. This required the | ||
| 181 | * des_SPtrans values in sp.h to be rotated 1 bit to the right. | ||
| 182 | * One perl script later and things have a 5% speed up on a sparc2. | ||
| 183 | * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> | ||
| 184 | * for pointing this out. */ | ||
| 185 | /* clear the top bits on machines with 8byte longs */ | ||
| 186 | r=ROTATE(r,29)&0xffffffffL; | ||
| 187 | l=ROTATE(l,29)&0xffffffffL; | ||
| 188 | |||
| 189 | s=(DES_LONG *)ks; | ||
| 190 | /* I don't know if it is worth the effort of loop unrolling the | ||
| 191 | * inner loop */ | ||
| 192 | if (enc) | ||
| 193 | { | ||
| 194 | #ifdef DES_UNROLL | ||
| 195 | D_ENCRYPT(l,r, 0); /* 1 */ | ||
| 196 | D_ENCRYPT(r,l, 2); /* 2 */ | ||
| 197 | D_ENCRYPT(l,r, 4); /* 3 */ | ||
| 198 | D_ENCRYPT(r,l, 6); /* 4 */ | ||
| 199 | D_ENCRYPT(l,r, 8); /* 5 */ | ||
| 200 | D_ENCRYPT(r,l,10); /* 6 */ | ||
| 201 | D_ENCRYPT(l,r,12); /* 7 */ | ||
| 202 | D_ENCRYPT(r,l,14); /* 8 */ | ||
| 203 | D_ENCRYPT(l,r,16); /* 9 */ | ||
| 204 | D_ENCRYPT(r,l,18); /* 10 */ | ||
| 205 | D_ENCRYPT(l,r,20); /* 11 */ | ||
| 206 | D_ENCRYPT(r,l,22); /* 12 */ | ||
| 207 | D_ENCRYPT(l,r,24); /* 13 */ | ||
| 208 | D_ENCRYPT(r,l,26); /* 14 */ | ||
| 209 | D_ENCRYPT(l,r,28); /* 15 */ | ||
| 210 | D_ENCRYPT(r,l,30); /* 16 */ | ||
| 211 | #else | ||
| 212 | for (i=0; i<32; i+=8) | ||
| 213 | { | ||
| 214 | D_ENCRYPT(l,r,i+0); /* 1 */ | ||
| 215 | D_ENCRYPT(r,l,i+2); /* 2 */ | ||
| 216 | D_ENCRYPT(l,r,i+4); /* 3 */ | ||
| 217 | D_ENCRYPT(r,l,i+6); /* 4 */ | ||
| 218 | } | ||
| 219 | #endif | ||
| 220 | } | ||
| 221 | else | ||
| 222 | { | ||
| 223 | #ifdef DES_UNROLL | ||
| 224 | D_ENCRYPT(l,r,30); /* 16 */ | ||
| 225 | D_ENCRYPT(r,l,28); /* 15 */ | ||
| 226 | D_ENCRYPT(l,r,26); /* 14 */ | ||
| 227 | D_ENCRYPT(r,l,24); /* 13 */ | ||
| 228 | D_ENCRYPT(l,r,22); /* 12 */ | ||
| 229 | D_ENCRYPT(r,l,20); /* 11 */ | ||
| 230 | D_ENCRYPT(l,r,18); /* 10 */ | ||
| 231 | D_ENCRYPT(r,l,16); /* 9 */ | ||
| 232 | D_ENCRYPT(l,r,14); /* 8 */ | ||
| 233 | D_ENCRYPT(r,l,12); /* 7 */ | ||
| 234 | D_ENCRYPT(l,r,10); /* 6 */ | ||
| 235 | D_ENCRYPT(r,l, 8); /* 5 */ | ||
| 236 | D_ENCRYPT(l,r, 6); /* 4 */ | ||
| 237 | D_ENCRYPT(r,l, 4); /* 3 */ | ||
| 238 | D_ENCRYPT(l,r, 2); /* 2 */ | ||
| 239 | D_ENCRYPT(r,l, 0); /* 1 */ | ||
| 240 | #else | ||
| 241 | for (i=30; i>0; i-=8) | ||
| 242 | { | ||
| 243 | D_ENCRYPT(l,r,i-0); /* 16 */ | ||
| 244 | D_ENCRYPT(r,l,i-2); /* 15 */ | ||
| 245 | D_ENCRYPT(l,r,i-4); /* 14 */ | ||
| 246 | D_ENCRYPT(r,l,i-6); /* 13 */ | ||
| 247 | } | ||
| 248 | #endif | ||
| 249 | } | ||
| 250 | /* rotate and clear the top bits on machines with 8byte longs */ | ||
| 251 | data[0]=ROTATE(l,3)&0xffffffffL; | ||
| 252 | data[1]=ROTATE(r,3)&0xffffffffL; | ||
| 253 | l=r=t=u=0; | ||
| 254 | } | ||
| 255 | |||
| 256 | void des_encrypt3(data,ks1,ks2,ks3) | ||
| 257 | DES_LONG *data; | ||
| 258 | des_key_schedule ks1; | ||
| 259 | des_key_schedule ks2; | ||
| 260 | des_key_schedule ks3; | ||
| 261 | { | ||
| 262 | register DES_LONG l,r; | ||
| 263 | |||
| 264 | l=data[0]; | ||
| 265 | r=data[1]; | ||
| 266 | IP(l,r); | ||
| 267 | data[0]=l; | ||
| 268 | data[1]=r; | ||
| 269 | des_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT); | ||
| 270 | des_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT); | ||
| 271 | des_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT); | ||
| 272 | l=data[0]; | ||
| 273 | r=data[1]; | ||
| 274 | FP(r,l); | ||
| 275 | data[0]=l; | ||
| 276 | data[1]=r; | ||
| 277 | } | ||
| 278 | |||
| 279 | void des_decrypt3(data,ks1,ks2,ks3) | ||
| 280 | DES_LONG *data; | ||
| 281 | des_key_schedule ks1; | ||
| 282 | des_key_schedule ks2; | ||
| 283 | des_key_schedule ks3; | ||
| 284 | { | ||
| 285 | register DES_LONG l,r; | ||
| 286 | |||
| 287 | l=data[0]; | ||
| 288 | r=data[1]; | ||
| 289 | IP(l,r); | ||
| 290 | data[0]=l; | ||
| 291 | data[1]=r; | ||
| 292 | des_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT); | ||
| 293 | des_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT); | ||
| 294 | des_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT); | ||
| 295 | l=data[0]; | ||
| 296 | r=data[1]; | ||
| 297 | FP(r,l); | ||
| 298 | data[0]=l; | ||
| 299 | data[1]=r; | ||
| 300 | } | ||
| 301 | |||
| 302 | #ifndef DES_DEFAULT_OPTIONS | ||
| 303 | |||
| 304 | void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) | ||
| 305 | des_cblock (*input); | ||
| 306 | des_cblock (*output); | ||
| 307 | long length; | ||
| 308 | des_key_schedule schedule; | ||
| 309 | des_cblock (*ivec); | ||
| 310 | int enc; | ||
| 311 | { | ||
| 312 | register DES_LONG tin0,tin1; | ||
| 313 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 314 | register unsigned char *in,*out; | ||
| 315 | register long l=length; | ||
| 316 | DES_LONG tin[2]; | ||
| 317 | unsigned char *iv; | ||
| 318 | |||
| 319 | in=(unsigned char *)input; | ||
| 320 | out=(unsigned char *)output; | ||
| 321 | iv=(unsigned char *)ivec; | ||
| 322 | |||
| 323 | if (enc) | ||
| 324 | { | ||
| 325 | c2l(iv,tout0); | ||
| 326 | c2l(iv,tout1); | ||
| 327 | for (l-=8; l>=0; l-=8) | ||
| 328 | { | ||
| 329 | c2l(in,tin0); | ||
| 330 | c2l(in,tin1); | ||
| 331 | tin0^=tout0; tin[0]=tin0; | ||
| 332 | tin1^=tout1; tin[1]=tin1; | ||
| 333 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 334 | tout0=tin[0]; l2c(tout0,out); | ||
| 335 | tout1=tin[1]; l2c(tout1,out); | ||
| 336 | } | ||
| 337 | if (l != -8) | ||
| 338 | { | ||
| 339 | c2ln(in,tin0,tin1,l+8); | ||
| 340 | tin0^=tout0; tin[0]=tin0; | ||
| 341 | tin1^=tout1; tin[1]=tin1; | ||
| 342 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 343 | tout0=tin[0]; l2c(tout0,out); | ||
| 344 | tout1=tin[1]; l2c(tout1,out); | ||
| 345 | } | ||
| 346 | iv=(unsigned char *)ivec; | ||
| 347 | l2c(tout0,iv); | ||
| 348 | l2c(tout1,iv); | ||
| 349 | } | ||
| 350 | else | ||
| 351 | { | ||
| 352 | c2l(iv,xor0); | ||
| 353 | c2l(iv,xor1); | ||
| 354 | for (l-=8; l>=0; l-=8) | ||
| 355 | { | ||
| 356 | c2l(in,tin0); tin[0]=tin0; | ||
| 357 | c2l(in,tin1); tin[1]=tin1; | ||
| 358 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 359 | tout0=tin[0]^xor0; | ||
| 360 | tout1=tin[1]^xor1; | ||
| 361 | l2c(tout0,out); | ||
| 362 | l2c(tout1,out); | ||
| 363 | xor0=tin0; | ||
| 364 | xor1=tin1; | ||
| 365 | } | ||
| 366 | if (l != -8) | ||
| 367 | { | ||
| 368 | c2l(in,tin0); tin[0]=tin0; | ||
| 369 | c2l(in,tin1); tin[1]=tin1; | ||
| 370 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 371 | tout0=tin[0]^xor0; | ||
| 372 | tout1=tin[1]^xor1; | ||
| 373 | l2cn(tout0,tout1,out,l+8); | ||
| 374 | xor0=tin0; | ||
| 375 | xor1=tin1; | ||
| 376 | } | ||
| 377 | |||
| 378 | iv=(unsigned char *)ivec; | ||
| 379 | l2c(xor0,iv); | ||
| 380 | l2c(xor1,iv); | ||
| 381 | } | ||
| 382 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 383 | tin[0]=tin[1]=0; | ||
| 384 | } | ||
| 385 | |||
| 386 | void des_ede3_cbc_encrypt(input, output, length, ks1, ks2, ks3, ivec, enc) | ||
| 387 | des_cblock (*input); | ||
| 388 | des_cblock (*output); | ||
| 389 | long length; | ||
| 390 | des_key_schedule ks1; | ||
| 391 | des_key_schedule ks2; | ||
| 392 | des_key_schedule ks3; | ||
| 393 | des_cblock (*ivec); | ||
| 394 | int enc; | ||
| 395 | { | ||
| 396 | register DES_LONG tin0,tin1; | ||
| 397 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 398 | register unsigned char *in,*out; | ||
| 399 | register long l=length; | ||
| 400 | DES_LONG tin[2]; | ||
| 401 | unsigned char *iv; | ||
| 402 | |||
| 403 | in=(unsigned char *)input; | ||
| 404 | out=(unsigned char *)output; | ||
| 405 | iv=(unsigned char *)ivec; | ||
| 406 | |||
| 407 | if (enc) | ||
| 408 | { | ||
| 409 | c2l(iv,tout0); | ||
| 410 | c2l(iv,tout1); | ||
| 411 | for (l-=8; l>=0; l-=8) | ||
| 412 | { | ||
| 413 | c2l(in,tin0); | ||
| 414 | c2l(in,tin1); | ||
| 415 | tin0^=tout0; | ||
| 416 | tin1^=tout1; | ||
| 417 | |||
| 418 | tin[0]=tin0; | ||
| 419 | tin[1]=tin1; | ||
| 420 | des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 421 | tout0=tin[0]; | ||
| 422 | tout1=tin[1]; | ||
| 423 | |||
| 424 | l2c(tout0,out); | ||
| 425 | l2c(tout1,out); | ||
| 426 | } | ||
| 427 | if (l != -8) | ||
| 428 | { | ||
| 429 | c2ln(in,tin0,tin1,l+8); | ||
| 430 | tin0^=tout0; | ||
| 431 | tin1^=tout1; | ||
| 432 | |||
| 433 | tin[0]=tin0; | ||
| 434 | tin[1]=tin1; | ||
| 435 | des_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 436 | tout0=tin[0]; | ||
| 437 | tout1=tin[1]; | ||
| 438 | |||
| 439 | l2c(tout0,out); | ||
| 440 | l2c(tout1,out); | ||
| 441 | } | ||
| 442 | iv=(unsigned char *)ivec; | ||
| 443 | l2c(tout0,iv); | ||
| 444 | l2c(tout1,iv); | ||
| 445 | } | ||
| 446 | else | ||
| 447 | { | ||
| 448 | register DES_LONG t0,t1; | ||
| 449 | |||
| 450 | c2l(iv,xor0); | ||
| 451 | c2l(iv,xor1); | ||
| 452 | for (l-=8; l>=0; l-=8) | ||
| 453 | { | ||
| 454 | c2l(in,tin0); | ||
| 455 | c2l(in,tin1); | ||
| 456 | |||
| 457 | t0=tin0; | ||
| 458 | t1=tin1; | ||
| 459 | |||
| 460 | tin[0]=tin0; | ||
| 461 | tin[1]=tin1; | ||
| 462 | des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 463 | tout0=tin[0]; | ||
| 464 | tout1=tin[1]; | ||
| 465 | |||
| 466 | tout0^=xor0; | ||
| 467 | tout1^=xor1; | ||
| 468 | l2c(tout0,out); | ||
| 469 | l2c(tout1,out); | ||
| 470 | xor0=t0; | ||
| 471 | xor1=t1; | ||
| 472 | } | ||
| 473 | if (l != -8) | ||
| 474 | { | ||
| 475 | c2l(in,tin0); | ||
| 476 | c2l(in,tin1); | ||
| 477 | |||
| 478 | t0=tin0; | ||
| 479 | t1=tin1; | ||
| 480 | |||
| 481 | tin[0]=tin0; | ||
| 482 | tin[1]=tin1; | ||
| 483 | des_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 484 | tout0=tin[0]; | ||
| 485 | tout1=tin[1]; | ||
| 486 | |||
| 487 | tout0^=xor0; | ||
| 488 | tout1^=xor1; | ||
| 489 | l2cn(tout0,tout1,out,l+8); | ||
| 490 | xor0=t0; | ||
| 491 | xor1=t1; | ||
| 492 | } | ||
| 493 | |||
| 494 | iv=(unsigned char *)ivec; | ||
| 495 | l2c(xor0,iv); | ||
| 496 | l2c(xor1,iv); | ||
| 497 | } | ||
| 498 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 499 | tin[0]=tin[1]=0; | ||
| 500 | } | ||
| 501 | |||
| 502 | #endif /* DES_DEFAULT_OPTIONS */ | ||
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c new file mode 100644 index 0000000000..140f6b5285 --- /dev/null +++ b/src/lib/libcrypto/des/ecb3_enc.c | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* crypto/des/ecb3_enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | void des_ecb3_encrypt(input, output, ks1, ks2, ks3, enc) | ||
| 62 | des_cblock (*input); | ||
| 63 | des_cblock (*output); | ||
| 64 | des_key_schedule ks1; | ||
| 65 | des_key_schedule ks2; | ||
| 66 | des_key_schedule ks3; | ||
| 67 | int enc; | ||
| 68 | { | ||
| 69 | register DES_LONG l0,l1; | ||
| 70 | register unsigned char *in,*out; | ||
| 71 | DES_LONG ll[2]; | ||
| 72 | |||
| 73 | in=(unsigned char *)input; | ||
| 74 | out=(unsigned char *)output; | ||
| 75 | c2l(in,l0); | ||
| 76 | c2l(in,l1); | ||
| 77 | ll[0]=l0; | ||
| 78 | ll[1]=l1; | ||
| 79 | if (enc) | ||
| 80 | des_encrypt3(ll,ks1,ks2,ks3); | ||
| 81 | else | ||
| 82 | des_decrypt3(ll,ks1,ks2,ks3); | ||
| 83 | l0=ll[0]; | ||
| 84 | l1=ll[1]; | ||
| 85 | l2c(l0,out); | ||
| 86 | l2c(l1,out); | ||
| 87 | } | ||
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c new file mode 100644 index 0000000000..acf23fdd00 --- /dev/null +++ b/src/lib/libcrypto/des/ecb_enc.c | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /* crypto/des/ecb_enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | #include "spr.h" | ||
| 61 | |||
| 62 | char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay"; | ||
| 63 | char *DES_version="DES part of SSLeay 0.9.0b 29-Jun-1998"; | ||
| 64 | |||
| 65 | char *des_options() | ||
| 66 | { | ||
| 67 | static int init=1; | ||
| 68 | static char buf[32]; | ||
| 69 | |||
| 70 | if (init) | ||
| 71 | { | ||
| 72 | char *ptr,*unroll,*risc,*size; | ||
| 73 | |||
| 74 | init=0; | ||
| 75 | #ifdef DES_PTR | ||
| 76 | ptr="ptr"; | ||
| 77 | #else | ||
| 78 | ptr="idx"; | ||
| 79 | #endif | ||
| 80 | #if defined(DES_RISC1) || defined(DES_RISC2) | ||
| 81 | #ifdef DES_RISC1 | ||
| 82 | risc="risc1"; | ||
| 83 | #endif | ||
| 84 | #ifdef DES_RISC2 | ||
| 85 | risc="risc2"; | ||
| 86 | #endif | ||
| 87 | #else | ||
| 88 | risc="cisc"; | ||
| 89 | #endif | ||
| 90 | #ifdef DES_UNROLL | ||
| 91 | unroll="16"; | ||
| 92 | #else | ||
| 93 | unroll="4"; | ||
| 94 | #endif | ||
| 95 | if (sizeof(DES_LONG) != sizeof(long)) | ||
| 96 | size="int"; | ||
| 97 | else | ||
| 98 | size="long"; | ||
| 99 | sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size); | ||
| 100 | } | ||
| 101 | return(buf); | ||
| 102 | } | ||
| 103 | |||
| 104 | |||
| 105 | void des_ecb_encrypt(input, output, ks, enc) | ||
| 106 | des_cblock (*input); | ||
| 107 | des_cblock (*output); | ||
| 108 | des_key_schedule ks; | ||
| 109 | int enc; | ||
| 110 | { | ||
| 111 | register DES_LONG l; | ||
| 112 | register unsigned char *in,*out; | ||
| 113 | DES_LONG ll[2]; | ||
| 114 | |||
| 115 | in=(unsigned char *)input; | ||
| 116 | out=(unsigned char *)output; | ||
| 117 | c2l(in,l); ll[0]=l; | ||
| 118 | c2l(in,l); ll[1]=l; | ||
| 119 | des_encrypt(ll,ks,enc); | ||
| 120 | l=ll[0]; l2c(l,out); | ||
| 121 | l=ll[1]; l2c(l,out); | ||
| 122 | l=ll[0]=ll[1]=0; | ||
| 123 | } | ||
| 124 | |||
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c new file mode 100644 index 0000000000..e08a904d75 --- /dev/null +++ b/src/lib/libcrypto/des/enc_read.c | |||
| @@ -0,0 +1,218 @@ | |||
| 1 | /* crypto/des/enc_read.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <errno.h> | ||
| 61 | #include "des_locl.h" | ||
| 62 | |||
| 63 | /* This has some uglies in it but it works - even over sockets. */ | ||
| 64 | /*extern int errno;*/ | ||
| 65 | int des_rw_mode=DES_PCBC_MODE; | ||
| 66 | |||
| 67 | int des_enc_read(fd, buf, len, sched, iv) | ||
| 68 | int fd; | ||
| 69 | char *buf; | ||
| 70 | int len; | ||
| 71 | des_key_schedule sched; | ||
| 72 | des_cblock (*iv); | ||
| 73 | { | ||
| 74 | /* data to be unencrypted */ | ||
| 75 | int net_num=0; | ||
| 76 | static unsigned char *net=NULL; | ||
| 77 | /* extra unencrypted data | ||
| 78 | * for when a block of 100 comes in but is des_read one byte at | ||
| 79 | * a time. */ | ||
| 80 | static char *unnet=NULL; | ||
| 81 | static int unnet_start=0; | ||
| 82 | static int unnet_left=0; | ||
| 83 | static char *tmpbuf=NULL; | ||
| 84 | int i; | ||
| 85 | long num=0,rnum; | ||
| 86 | unsigned char *p; | ||
| 87 | |||
| 88 | if (tmpbuf == NULL) | ||
| 89 | { | ||
| 90 | tmpbuf=(char *)malloc(BSIZE); | ||
| 91 | if (tmpbuf == NULL) return(-1); | ||
| 92 | } | ||
| 93 | if (net == NULL) | ||
| 94 | { | ||
| 95 | net=(unsigned char *)malloc(BSIZE); | ||
| 96 | if (net == NULL) return(-1); | ||
| 97 | } | ||
| 98 | if (unnet == NULL) | ||
| 99 | { | ||
| 100 | unnet=(char *)malloc(BSIZE); | ||
| 101 | if (unnet == NULL) return(-1); | ||
| 102 | } | ||
| 103 | /* left over data from last decrypt */ | ||
| 104 | if (unnet_left != 0) | ||
| 105 | { | ||
| 106 | if (unnet_left < len) | ||
| 107 | { | ||
| 108 | /* we still still need more data but will return | ||
| 109 | * with the number of bytes we have - should always | ||
| 110 | * check the return value */ | ||
| 111 | memcpy(buf,&(unnet[unnet_start]), | ||
| 112 | (unsigned int)unnet_left); | ||
| 113 | /* eay 26/08/92 I had the next 2 lines | ||
| 114 | * reversed :-( */ | ||
| 115 | i=unnet_left; | ||
| 116 | unnet_start=unnet_left=0; | ||
| 117 | } | ||
| 118 | else | ||
| 119 | { | ||
| 120 | memcpy(buf,&(unnet[unnet_start]),(unsigned int)len); | ||
| 121 | unnet_start+=len; | ||
| 122 | unnet_left-=len; | ||
| 123 | i=len; | ||
| 124 | } | ||
| 125 | return(i); | ||
| 126 | } | ||
| 127 | |||
| 128 | /* We need to get more data. */ | ||
| 129 | if (len > MAXWRITE) len=MAXWRITE; | ||
| 130 | |||
| 131 | /* first - get the length */ | ||
| 132 | while (net_num < HDRSIZE) | ||
| 133 | { | ||
| 134 | i=read(fd,&(net[net_num]),(unsigned int)HDRSIZE-net_num); | ||
| 135 | #ifdef EINTR | ||
| 136 | if ((i == -1) && (errno == EINTR)) continue; | ||
| 137 | #endif | ||
| 138 | if (i <= 0) return(0); | ||
| 139 | net_num+=i; | ||
| 140 | } | ||
| 141 | |||
| 142 | /* we now have at net_num bytes in net */ | ||
| 143 | p=net; | ||
| 144 | /* num=0; */ | ||
| 145 | n2l(p,num); | ||
| 146 | /* num should be rounded up to the next group of eight | ||
| 147 | * we make sure that we have read a multiple of 8 bytes from the net. | ||
| 148 | */ | ||
| 149 | if ((num > MAXWRITE) || (num < 0)) /* error */ | ||
| 150 | return(-1); | ||
| 151 | rnum=(num < 8)?8:((num+7)/8*8); | ||
| 152 | |||
| 153 | net_num=0; | ||
| 154 | while (net_num < rnum) | ||
| 155 | { | ||
| 156 | i=read(fd,&(net[net_num]),(unsigned int)rnum-net_num); | ||
| 157 | #ifdef EINTR | ||
| 158 | if ((i == -1) && (errno == EINTR)) continue; | ||
| 159 | #endif | ||
| 160 | if (i <= 0) return(0); | ||
| 161 | net_num+=i; | ||
| 162 | } | ||
| 163 | |||
| 164 | /* Check if there will be data left over. */ | ||
| 165 | if (len < num) | ||
| 166 | { | ||
| 167 | if (des_rw_mode & DES_PCBC_MODE) | ||
| 168 | des_pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet, | ||
| 169 | num,sched,iv,DES_DECRYPT); | ||
| 170 | else | ||
| 171 | des_cbc_encrypt((des_cblock *)net,(des_cblock *)unnet, | ||
| 172 | num,sched,iv,DES_DECRYPT); | ||
| 173 | memcpy(buf,unnet,(unsigned int)len); | ||
| 174 | unnet_start=len; | ||
| 175 | unnet_left=(int)num-len; | ||
| 176 | |||
| 177 | /* The following line is done because we return num | ||
| 178 | * as the number of bytes read. */ | ||
| 179 | num=len; | ||
| 180 | } | ||
| 181 | else | ||
| 182 | { | ||
| 183 | /* >output is a multiple of 8 byes, if len < rnum | ||
| 184 | * >we must be careful. The user must be aware that this | ||
| 185 | * >routine will write more bytes than he asked for. | ||
| 186 | * >The length of the buffer must be correct. | ||
| 187 | * FIXED - Should be ok now 18-9-90 - eay */ | ||
| 188 | if (len < rnum) | ||
| 189 | { | ||
| 190 | |||
| 191 | if (des_rw_mode & DES_PCBC_MODE) | ||
| 192 | des_pcbc_encrypt((des_cblock *)net, | ||
| 193 | (des_cblock *)tmpbuf, | ||
| 194 | num,sched,iv,DES_DECRYPT); | ||
| 195 | else | ||
| 196 | des_cbc_encrypt((des_cblock *)net, | ||
| 197 | (des_cblock *)tmpbuf, | ||
| 198 | num,sched,iv,DES_DECRYPT); | ||
| 199 | |||
| 200 | /* eay 26/08/92 fix a bug that returned more | ||
| 201 | * bytes than you asked for (returned len bytes :-( */ | ||
| 202 | memcpy(buf,tmpbuf,(unsigned int)num); | ||
| 203 | } | ||
| 204 | else | ||
| 205 | { | ||
| 206 | if (des_rw_mode & DES_PCBC_MODE) | ||
| 207 | des_pcbc_encrypt((des_cblock *)net, | ||
| 208 | (des_cblock *)buf,num,sched,iv, | ||
| 209 | DES_DECRYPT); | ||
| 210 | else | ||
| 211 | des_cbc_encrypt((des_cblock *)net, | ||
| 212 | (des_cblock *)buf,num,sched,iv, | ||
| 213 | DES_DECRYPT); | ||
| 214 | } | ||
| 215 | } | ||
| 216 | return((int)num); | ||
| 217 | } | ||
| 218 | |||
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c new file mode 100644 index 0000000000..29a7330fb0 --- /dev/null +++ b/src/lib/libcrypto/des/enc_writ.c | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | /* crypto/des/enc_writ.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <errno.h> | ||
| 60 | #include <time.h> | ||
| 61 | #include "des_locl.h" | ||
| 62 | |||
| 63 | int des_enc_write(fd, buf, len, sched, iv) | ||
| 64 | int fd; | ||
| 65 | char *buf; | ||
| 66 | int len; | ||
| 67 | des_key_schedule sched; | ||
| 68 | des_cblock (*iv); | ||
| 69 | { | ||
| 70 | #ifdef _LIBC | ||
| 71 | extern int srandom(); | ||
| 72 | extern unsigned long time(); | ||
| 73 | extern int random(); | ||
| 74 | extern int write(); | ||
| 75 | #endif | ||
| 76 | |||
| 77 | long rnum; | ||
| 78 | int i,j,k,outnum; | ||
| 79 | static char *outbuf=NULL; | ||
| 80 | char shortbuf[8]; | ||
| 81 | char *p; | ||
| 82 | static int start=1; | ||
| 83 | |||
| 84 | if (outbuf == NULL) | ||
| 85 | { | ||
| 86 | outbuf=(char *)malloc(BSIZE+HDRSIZE); | ||
| 87 | if (outbuf == NULL) return(-1); | ||
| 88 | } | ||
| 89 | /* If we are sending less than 8 bytes, the same char will look | ||
| 90 | * the same if we don't pad it out with random bytes */ | ||
| 91 | if (start) | ||
| 92 | { | ||
| 93 | start=0; | ||
| 94 | srandom((unsigned int)time(NULL)); | ||
| 95 | } | ||
| 96 | |||
| 97 | /* lets recurse if we want to send the data in small chunks */ | ||
| 98 | if (len > MAXWRITE) | ||
| 99 | { | ||
| 100 | j=0; | ||
| 101 | for (i=0; i<len; i+=k) | ||
| 102 | { | ||
| 103 | k=des_enc_write(fd,&(buf[i]), | ||
| 104 | ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv); | ||
| 105 | if (k < 0) | ||
| 106 | return(k); | ||
| 107 | else | ||
| 108 | j+=k; | ||
| 109 | } | ||
| 110 | return(j); | ||
| 111 | } | ||
| 112 | |||
| 113 | /* write length first */ | ||
| 114 | p=outbuf; | ||
| 115 | l2n(len,p); | ||
| 116 | |||
| 117 | /* pad short strings */ | ||
| 118 | if (len < 8) | ||
| 119 | { | ||
| 120 | p=shortbuf; | ||
| 121 | memcpy(shortbuf,buf,(unsigned int)len); | ||
| 122 | for (i=len; i<8; i++) | ||
| 123 | shortbuf[i]=random(); | ||
| 124 | rnum=8; | ||
| 125 | } | ||
| 126 | else | ||
| 127 | { | ||
| 128 | p=buf; | ||
| 129 | rnum=((len+7)/8*8); /* round up to nearest eight */ | ||
| 130 | } | ||
| 131 | |||
| 132 | if (des_rw_mode & DES_PCBC_MODE) | ||
| 133 | des_pcbc_encrypt((des_cblock *)p, | ||
| 134 | (des_cblock *)&(outbuf[HDRSIZE]), | ||
| 135 | (long)((len<8)?8:len),sched,iv,DES_ENCRYPT); | ||
| 136 | else | ||
| 137 | des_cbc_encrypt((des_cblock *)p, | ||
| 138 | (des_cblock *)&(outbuf[HDRSIZE]), | ||
| 139 | (long)((len<8)?8:len),sched,iv,DES_ENCRYPT); | ||
| 140 | |||
| 141 | /* output */ | ||
| 142 | outnum=(int)rnum+HDRSIZE; | ||
| 143 | |||
| 144 | for (j=0; j<outnum; j+=i) | ||
| 145 | { | ||
| 146 | /* eay 26/08/92 I was not doing writing from where we | ||
| 147 | * got upto. */ | ||
| 148 | i=write(fd,&(outbuf[j]),(unsigned int)(outnum-j)); | ||
| 149 | if (i == -1) | ||
| 150 | { | ||
| 151 | if (errno == EINTR) | ||
| 152 | i=0; | ||
| 153 | else /* This is really a bad error - very bad | ||
| 154 | * It will stuff-up both ends. */ | ||
| 155 | return(-1); | ||
| 156 | } | ||
| 157 | } | ||
| 158 | |||
| 159 | return(len); | ||
| 160 | } | ||
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c new file mode 100644 index 0000000000..129beb27da --- /dev/null +++ b/src/lib/libcrypto/des/fcrypt.c | |||
| @@ -0,0 +1,153 @@ | |||
| 1 | /* NOCW */ | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | /* This version of crypt has been developed from my MIT compatable | ||
| 5 | * DES library. | ||
| 6 | * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au | ||
| 7 | * Eric Young (eay@cryptsoft.com) | ||
| 8 | */ | ||
| 9 | |||
| 10 | /* Modification by Jens Kupferschmidt (Cu) | ||
| 11 | * I have included directive PARA for shared memory computers. | ||
| 12 | * I have included a directive LONGCRYPT to using this routine to cipher | ||
| 13 | * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN | ||
| 14 | * definition is the maximum of lenght of password and can changed. I have | ||
| 15 | * defined 24. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "des_locl.h" | ||
| 19 | |||
| 20 | /* Added more values to handle illegal salt values the way normal | ||
| 21 | * crypt() implementations do. The patch was sent by | ||
| 22 | * Bjorn Gronvall <bg@sics.se> | ||
| 23 | */ | ||
| 24 | static unsigned const char con_salt[128]={ | ||
| 25 | 0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9, | ||
| 26 | 0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1, | ||
| 27 | 0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9, | ||
| 28 | 0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1, | ||
| 29 | 0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9, | ||
| 30 | 0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01, | ||
| 31 | 0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, | ||
| 32 | 0x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A, | ||
| 33 | 0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12, | ||
| 34 | 0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A, | ||
| 35 | 0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22, | ||
| 36 | 0x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24, | ||
| 37 | 0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C, | ||
| 38 | 0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34, | ||
| 39 | 0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C, | ||
| 40 | 0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44, | ||
| 41 | }; | ||
| 42 | |||
| 43 | static unsigned const char cov_2char[64]={ | ||
| 44 | 0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35, | ||
| 45 | 0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44, | ||
| 46 | 0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C, | ||
| 47 | 0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54, | ||
| 48 | 0x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62, | ||
| 49 | 0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A, | ||
| 50 | 0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72, | ||
| 51 | 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A | ||
| 52 | }; | ||
| 53 | |||
| 54 | #ifndef NOPROTO | ||
| 55 | void fcrypt_body(DES_LONG *out,des_key_schedule ks, | ||
| 56 | DES_LONG Eswap0, DES_LONG Eswap1); | ||
| 57 | |||
| 58 | #if defined(PERL5) || defined(FreeBSD) | ||
| 59 | char *des_crypt(const char *buf,const char *salt); | ||
| 60 | #else | ||
| 61 | char *crypt(const char *buf,const char *salt); | ||
| 62 | #endif | ||
| 63 | #else | ||
| 64 | void fcrypt_body(); | ||
| 65 | #ifdef PERL5 | ||
| 66 | char *des_crypt(); | ||
| 67 | #else | ||
| 68 | char *crypt(); | ||
| 69 | #endif | ||
| 70 | #endif | ||
| 71 | |||
| 72 | #if defined(PERL5) || defined(FreeBSD) | ||
| 73 | char *des_crypt(buf,salt) | ||
| 74 | #else | ||
| 75 | char *crypt(buf,salt) | ||
| 76 | #endif | ||
| 77 | const char *buf; | ||
| 78 | const char *salt; | ||
| 79 | { | ||
| 80 | static char buff[14]; | ||
| 81 | |||
| 82 | return(des_fcrypt(buf,salt,buff)); | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | char *des_fcrypt(buf,salt,ret) | ||
| 87 | const char *buf; | ||
| 88 | const char *salt; | ||
| 89 | char *ret; | ||
| 90 | { | ||
| 91 | unsigned int i,j,x,y; | ||
| 92 | DES_LONG Eswap0,Eswap1; | ||
| 93 | DES_LONG out[2],ll; | ||
| 94 | des_cblock key; | ||
| 95 | des_key_schedule ks; | ||
| 96 | unsigned char bb[9]; | ||
| 97 | unsigned char *b=bb; | ||
| 98 | unsigned char c,u; | ||
| 99 | |||
| 100 | /* eay 25/08/92 | ||
| 101 | * If you call crypt("pwd","*") as often happens when you | ||
| 102 | * have * as the pwd field in /etc/passwd, the function | ||
| 103 | * returns *\0XXXXXXXXX | ||
| 104 | * The \0 makes the string look like * so the pwd "*" would | ||
| 105 | * crypt to "*". This was found when replacing the crypt in | ||
| 106 | * our shared libraries. People found that the disbled | ||
| 107 | * accounts effectivly had no passwd :-(. */ | ||
| 108 | x=ret[0]=((salt[0] == '\0')?'A':salt[0]); | ||
| 109 | Eswap0=con_salt[x]<<2; | ||
| 110 | x=ret[1]=((salt[1] == '\0')?'A':salt[1]); | ||
| 111 | Eswap1=con_salt[x]<<6; | ||
| 112 | |||
| 113 | /* EAY | ||
| 114 | r=strlen(buf); | ||
| 115 | r=(r+7)/8; | ||
| 116 | */ | ||
| 117 | for (i=0; i<8; i++) | ||
| 118 | { | ||
| 119 | c= *(buf++); | ||
| 120 | if (!c) break; | ||
| 121 | key[i]=(c<<1); | ||
| 122 | } | ||
| 123 | for (; i<8; i++) | ||
| 124 | key[i]=0; | ||
| 125 | |||
| 126 | des_set_key((des_cblock *)(key),ks); | ||
| 127 | fcrypt_body(&(out[0]),ks,Eswap0,Eswap1); | ||
| 128 | |||
| 129 | ll=out[0]; l2c(ll,b); | ||
| 130 | ll=out[1]; l2c(ll,b); | ||
| 131 | y=0; | ||
| 132 | u=0x80; | ||
| 133 | bb[8]=0; | ||
| 134 | for (i=2; i<13; i++) | ||
| 135 | { | ||
| 136 | c=0; | ||
| 137 | for (j=0; j<6; j++) | ||
| 138 | { | ||
| 139 | c<<=1; | ||
| 140 | if (bb[y] & u) c|=1; | ||
| 141 | u>>=1; | ||
| 142 | if (!u) | ||
| 143 | { | ||
| 144 | y++; | ||
| 145 | u=0x80; | ||
| 146 | } | ||
| 147 | } | ||
| 148 | ret[i]=cov_2char[c]; | ||
| 149 | } | ||
| 150 | ret[13]='\0'; | ||
| 151 | return(ret); | ||
| 152 | } | ||
| 153 | |||
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c new file mode 100644 index 0000000000..1544634bc1 --- /dev/null +++ b/src/lib/libcrypto/des/fcrypt_b.c | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | /* crypto/des/fcrypt_b.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | |||
| 61 | /* This version of crypt has been developed from my MIT compatable | ||
| 62 | * DES library. | ||
| 63 | * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au | ||
| 64 | * Eric Young (eay@cryptsoft.com) | ||
| 65 | */ | ||
| 66 | |||
| 67 | #define DES_FCRYPT | ||
| 68 | #include "des_locl.h" | ||
| 69 | #undef DES_FCRYPT | ||
| 70 | |||
| 71 | #undef PERM_OP | ||
| 72 | #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ | ||
| 73 | (b)^=(t),\ | ||
| 74 | (a)^=((t)<<(n))) | ||
| 75 | |||
| 76 | #undef HPERM_OP | ||
| 77 | #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ | ||
| 78 | (a)=(a)^(t)^(t>>(16-(n))))\ | ||
| 79 | |||
| 80 | void fcrypt_body(out, ks, Eswap0, Eswap1) | ||
| 81 | DES_LONG *out; | ||
| 82 | des_key_schedule ks; | ||
| 83 | DES_LONG Eswap0; | ||
| 84 | DES_LONG Eswap1; | ||
| 85 | { | ||
| 86 | register DES_LONG l,r,t,u; | ||
| 87 | #ifdef DES_PTR | ||
| 88 | register unsigned char *des_SP=(unsigned char *)des_SPtrans; | ||
| 89 | #endif | ||
| 90 | register DES_LONG *s; | ||
| 91 | register int j; | ||
| 92 | register DES_LONG E0,E1; | ||
| 93 | |||
| 94 | l=0; | ||
| 95 | r=0; | ||
| 96 | |||
| 97 | s=(DES_LONG *)ks; | ||
| 98 | E0=Eswap0; | ||
| 99 | E1=Eswap1; | ||
| 100 | |||
| 101 | for (j=0; j<25; j++) | ||
| 102 | { | ||
| 103 | #ifdef DES_UNROLL | ||
| 104 | register int i; | ||
| 105 | |||
| 106 | for (i=0; i<32; i+=8) | ||
| 107 | { | ||
| 108 | D_ENCRYPT(l,r,i+0); /* 1 */ | ||
| 109 | D_ENCRYPT(r,l,i+2); /* 2 */ | ||
| 110 | D_ENCRYPT(l,r,i+4); /* 1 */ | ||
| 111 | D_ENCRYPT(r,l,i+6); /* 2 */ | ||
| 112 | } | ||
| 113 | #else | ||
| 114 | D_ENCRYPT(l,r, 0); /* 1 */ | ||
| 115 | D_ENCRYPT(r,l, 2); /* 2 */ | ||
| 116 | D_ENCRYPT(l,r, 4); /* 3 */ | ||
| 117 | D_ENCRYPT(r,l, 6); /* 4 */ | ||
| 118 | D_ENCRYPT(l,r, 8); /* 5 */ | ||
| 119 | D_ENCRYPT(r,l,10); /* 6 */ | ||
| 120 | D_ENCRYPT(l,r,12); /* 7 */ | ||
| 121 | D_ENCRYPT(r,l,14); /* 8 */ | ||
| 122 | D_ENCRYPT(l,r,16); /* 9 */ | ||
| 123 | D_ENCRYPT(r,l,18); /* 10 */ | ||
| 124 | D_ENCRYPT(l,r,20); /* 11 */ | ||
| 125 | D_ENCRYPT(r,l,22); /* 12 */ | ||
| 126 | D_ENCRYPT(l,r,24); /* 13 */ | ||
| 127 | D_ENCRYPT(r,l,26); /* 14 */ | ||
| 128 | D_ENCRYPT(l,r,28); /* 15 */ | ||
| 129 | D_ENCRYPT(r,l,30); /* 16 */ | ||
| 130 | #endif | ||
| 131 | |||
| 132 | t=l; | ||
| 133 | l=r; | ||
| 134 | r=t; | ||
| 135 | } | ||
| 136 | l=ROTATE(l,3)&0xffffffffL; | ||
| 137 | r=ROTATE(r,3)&0xffffffffL; | ||
| 138 | |||
| 139 | PERM_OP(l,r,t, 1,0x55555555L); | ||
| 140 | PERM_OP(r,l,t, 8,0x00ff00ffL); | ||
| 141 | PERM_OP(l,r,t, 2,0x33333333L); | ||
| 142 | PERM_OP(r,l,t,16,0x0000ffffL); | ||
| 143 | PERM_OP(l,r,t, 4,0x0f0f0f0fL); | ||
| 144 | |||
| 145 | out[0]=r; | ||
| 146 | out[1]=l; | ||
| 147 | } | ||
| 148 | |||
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c new file mode 100644 index 0000000000..1d1a368c22 --- /dev/null +++ b/src/lib/libcrypto/des/ncbc_enc.c | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | /* crypto/des/ncbc_enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | void des_ncbc_encrypt(input, output, length, schedule, ivec, enc) | ||
| 62 | des_cblock (*input); | ||
| 63 | des_cblock (*output); | ||
| 64 | long length; | ||
| 65 | des_key_schedule schedule; | ||
| 66 | des_cblock (*ivec); | ||
| 67 | int enc; | ||
| 68 | { | ||
| 69 | register DES_LONG tin0,tin1; | ||
| 70 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 71 | register unsigned char *in,*out; | ||
| 72 | register long l=length; | ||
| 73 | DES_LONG tin[2]; | ||
| 74 | unsigned char *iv; | ||
| 75 | |||
| 76 | in=(unsigned char *)input; | ||
| 77 | out=(unsigned char *)output; | ||
| 78 | iv=(unsigned char *)ivec; | ||
| 79 | |||
| 80 | if (enc) | ||
| 81 | { | ||
| 82 | c2l(iv,tout0); | ||
| 83 | c2l(iv,tout1); | ||
| 84 | for (l-=8; l>=0; l-=8) | ||
| 85 | { | ||
| 86 | c2l(in,tin0); | ||
| 87 | c2l(in,tin1); | ||
| 88 | tin0^=tout0; tin[0]=tin0; | ||
| 89 | tin1^=tout1; tin[1]=tin1; | ||
| 90 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 91 | tout0=tin[0]; l2c(tout0,out); | ||
| 92 | tout1=tin[1]; l2c(tout1,out); | ||
| 93 | } | ||
| 94 | if (l != -8) | ||
| 95 | { | ||
| 96 | c2ln(in,tin0,tin1,l+8); | ||
| 97 | tin0^=tout0; tin[0]=tin0; | ||
| 98 | tin1^=tout1; tin[1]=tin1; | ||
| 99 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 100 | tout0=tin[0]; l2c(tout0,out); | ||
| 101 | tout1=tin[1]; l2c(tout1,out); | ||
| 102 | } | ||
| 103 | iv=(unsigned char *)ivec; | ||
| 104 | l2c(tout0,iv); | ||
| 105 | l2c(tout1,iv); | ||
| 106 | } | ||
| 107 | else | ||
| 108 | { | ||
| 109 | c2l(iv,xor0); | ||
| 110 | c2l(iv,xor1); | ||
| 111 | for (l-=8; l>=0; l-=8) | ||
| 112 | { | ||
| 113 | c2l(in,tin0); tin[0]=tin0; | ||
| 114 | c2l(in,tin1); tin[1]=tin1; | ||
| 115 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 116 | tout0=tin[0]^xor0; | ||
| 117 | tout1=tin[1]^xor1; | ||
| 118 | l2c(tout0,out); | ||
| 119 | l2c(tout1,out); | ||
| 120 | xor0=tin0; | ||
| 121 | xor1=tin1; | ||
| 122 | } | ||
| 123 | iv=(unsigned char *)ivec; | ||
| 124 | l2c(xor0,iv); | ||
| 125 | l2c(xor1,iv); | ||
| 126 | } | ||
| 127 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 128 | tin[0]=tin[1]=0; | ||
| 129 | } | ||
| 130 | |||
diff --git a/src/lib/libcrypto/des/ofb64ede.c b/src/lib/libcrypto/des/ofb64ede.c new file mode 100644 index 0000000000..4b1b0199f1 --- /dev/null +++ b/src/lib/libcrypto/des/ofb64ede.c | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* crypto/des/ofb64ede.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit ofb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | void des_ede3_ofb64_encrypt(in, out, length, k1,k2,k3, ivec, num) | ||
| 66 | register unsigned char *in; | ||
| 67 | register unsigned char *out; | ||
| 68 | long length; | ||
| 69 | des_key_schedule k1,k2,k3; | ||
| 70 | des_cblock (*ivec); | ||
| 71 | int *num; | ||
| 72 | { | ||
| 73 | register DES_LONG v0,v1; | ||
| 74 | register int n= *num; | ||
| 75 | register long l=length; | ||
| 76 | des_cblock d; | ||
| 77 | register char *dp; | ||
| 78 | DES_LONG ti[2]; | ||
| 79 | unsigned char *iv; | ||
| 80 | int save=0; | ||
| 81 | |||
| 82 | iv=(unsigned char *)ivec; | ||
| 83 | c2l(iv,v0); | ||
| 84 | c2l(iv,v1); | ||
| 85 | ti[0]=v0; | ||
| 86 | ti[1]=v1; | ||
| 87 | dp=(char *)d; | ||
| 88 | l2c(v0,dp); | ||
| 89 | l2c(v1,dp); | ||
| 90 | while (l--) | ||
| 91 | { | ||
| 92 | if (n == 0) | ||
| 93 | { | ||
| 94 | /* ti[0]=v0; */ | ||
| 95 | /* ti[1]=v1; */ | ||
| 96 | des_encrypt3((DES_LONG *)ti,k1,k2,k3); | ||
| 97 | v0=ti[0]; | ||
| 98 | v1=ti[1]; | ||
| 99 | |||
| 100 | dp=(char *)d; | ||
| 101 | l2c(v0,dp); | ||
| 102 | l2c(v1,dp); | ||
| 103 | save++; | ||
| 104 | } | ||
| 105 | *(out++)= *(in++)^d[n]; | ||
| 106 | n=(n+1)&0x07; | ||
| 107 | } | ||
| 108 | if (save) | ||
| 109 | { | ||
| 110 | /* v0=ti[0]; | ||
| 111 | v1=ti[1];*/ | ||
| 112 | iv=(unsigned char *)ivec; | ||
| 113 | l2c(v0,iv); | ||
| 114 | l2c(v1,iv); | ||
| 115 | } | ||
| 116 | v0=v1=ti[0]=ti[1]=0; | ||
| 117 | *num=n; | ||
| 118 | } | ||
| 119 | |||
| 120 | #ifdef undef /* MACRO */ | ||
| 121 | void des_ede2_ofb64_encrypt(in, out, length, k1,k2, ivec, num) | ||
| 122 | register unsigned char *in; | ||
| 123 | register unsigned char *out; | ||
| 124 | long length; | ||
| 125 | des_key_schedule k1,k2; | ||
| 126 | des_cblock (*ivec); | ||
| 127 | int *num; | ||
| 128 | { | ||
| 129 | des_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num); | ||
| 130 | } | ||
| 131 | #endif | ||
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c new file mode 100644 index 0000000000..ea7e612697 --- /dev/null +++ b/src/lib/libcrypto/des/ofb64enc.c | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | /* crypto/des/ofb64enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit ofb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | void des_ofb64_encrypt(in, out, length, schedule, ivec, num) | ||
| 66 | register unsigned char *in; | ||
| 67 | register unsigned char *out; | ||
| 68 | long length; | ||
| 69 | des_key_schedule schedule; | ||
| 70 | des_cblock (*ivec); | ||
| 71 | int *num; | ||
| 72 | { | ||
| 73 | register DES_LONG v0,v1,t; | ||
| 74 | register int n= *num; | ||
| 75 | register long l=length; | ||
| 76 | des_cblock d; | ||
| 77 | register char *dp; | ||
| 78 | DES_LONG ti[2]; | ||
| 79 | unsigned char *iv; | ||
| 80 | int save=0; | ||
| 81 | |||
| 82 | iv=(unsigned char *)ivec; | ||
| 83 | c2l(iv,v0); | ||
| 84 | c2l(iv,v1); | ||
| 85 | ti[0]=v0; | ||
| 86 | ti[1]=v1; | ||
| 87 | dp=(char *)d; | ||
| 88 | l2c(v0,dp); | ||
| 89 | l2c(v1,dp); | ||
| 90 | while (l--) | ||
| 91 | { | ||
| 92 | if (n == 0) | ||
| 93 | { | ||
| 94 | des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 95 | dp=(char *)d; | ||
| 96 | t=ti[0]; l2c(t,dp); | ||
| 97 | t=ti[1]; l2c(t,dp); | ||
| 98 | save++; | ||
| 99 | } | ||
| 100 | *(out++)= *(in++)^d[n]; | ||
| 101 | n=(n+1)&0x07; | ||
| 102 | } | ||
| 103 | if (save) | ||
| 104 | { | ||
| 105 | v0=ti[0]; | ||
| 106 | v1=ti[1]; | ||
| 107 | iv=(unsigned char *)ivec; | ||
| 108 | l2c(v0,iv); | ||
| 109 | l2c(v1,iv); | ||
| 110 | } | ||
| 111 | t=v0=v1=ti[0]=ti[1]=0; | ||
| 112 | *num=n; | ||
| 113 | } | ||
| 114 | |||
diff --git a/src/lib/libcrypto/des/ofb_enc.c b/src/lib/libcrypto/des/ofb_enc.c new file mode 100644 index 0000000000..4db0cdbd60 --- /dev/null +++ b/src/lib/libcrypto/des/ofb_enc.c | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | /* crypto/des/ofb_enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output are loaded in multiples of 8 bits. | ||
| 62 | * What this means is that if you hame numbits=12 and length=2 | ||
| 63 | * the first 12 bits will be retrieved from the first byte and half | ||
| 64 | * the second. The second 12 bits will come from the 3rd and half the 4th | ||
| 65 | * byte. | ||
| 66 | */ | ||
| 67 | void des_ofb_encrypt(in, out, numbits, length, schedule, ivec) | ||
| 68 | unsigned char *in; | ||
| 69 | unsigned char *out; | ||
| 70 | int numbits; | ||
| 71 | long length; | ||
| 72 | des_key_schedule schedule; | ||
| 73 | des_cblock (*ivec); | ||
| 74 | { | ||
| 75 | register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8; | ||
| 76 | register DES_LONG mask0,mask1; | ||
| 77 | register long l=length; | ||
| 78 | register int num=numbits; | ||
| 79 | DES_LONG ti[2]; | ||
| 80 | unsigned char *iv; | ||
| 81 | |||
| 82 | if (num > 64) return; | ||
| 83 | if (num > 32) | ||
| 84 | { | ||
| 85 | mask0=0xffffffffL; | ||
| 86 | if (num >= 64) | ||
| 87 | mask1=mask0; | ||
| 88 | else | ||
| 89 | mask1=(1L<<(num-32))-1; | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | if (num == 32) | ||
| 94 | mask0=0xffffffffL; | ||
| 95 | else | ||
| 96 | mask0=(1L<<num)-1; | ||
| 97 | mask1=0x00000000L; | ||
| 98 | } | ||
| 99 | |||
| 100 | iv=(unsigned char *)ivec; | ||
| 101 | c2l(iv,v0); | ||
| 102 | c2l(iv,v1); | ||
| 103 | ti[0]=v0; | ||
| 104 | ti[1]=v1; | ||
| 105 | while (l-- > 0) | ||
| 106 | { | ||
| 107 | ti[0]=v0; | ||
| 108 | ti[1]=v1; | ||
| 109 | des_encrypt((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 110 | vv0=ti[0]; | ||
| 111 | vv1=ti[1]; | ||
| 112 | c2ln(in,d0,d1,n); | ||
| 113 | in+=n; | ||
| 114 | d0=(d0^vv0)&mask0; | ||
| 115 | d1=(d1^vv1)&mask1; | ||
| 116 | l2cn(d0,d1,out,n); | ||
| 117 | out+=n; | ||
| 118 | |||
| 119 | if (num == 32) | ||
| 120 | { v0=v1; v1=vv0; } | ||
| 121 | else if (num == 64) | ||
| 122 | { v0=vv0; v1=vv1; } | ||
| 123 | else if (num > 32) /* && num != 64 */ | ||
| 124 | { | ||
| 125 | v0=((v1>>(num-32))|(vv0<<(64-num)))&0xffffffffL; | ||
| 126 | v1=((vv0>>(num-32))|(vv1<<(64-num)))&0xffffffffL; | ||
| 127 | } | ||
| 128 | else /* num < 32 */ | ||
| 129 | { | ||
| 130 | v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL; | ||
| 131 | v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | iv=(unsigned char *)ivec; | ||
| 135 | l2c(v0,iv); | ||
| 136 | l2c(v1,iv); | ||
| 137 | v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0; | ||
| 138 | } | ||
| 139 | |||
diff --git a/src/lib/libcrypto/des/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c new file mode 100644 index 0000000000..4513207d90 --- /dev/null +++ b/src/lib/libcrypto/des/pcbc_enc.c | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | /* crypto/des/pcbc_enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | void des_pcbc_encrypt(input, output, length, schedule, ivec, enc) | ||
| 62 | des_cblock (*input); | ||
| 63 | des_cblock (*output); | ||
| 64 | long length; | ||
| 65 | des_key_schedule schedule; | ||
| 66 | des_cblock (*ivec); | ||
| 67 | int enc; | ||
| 68 | { | ||
| 69 | register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1; | ||
| 70 | DES_LONG tin[2]; | ||
| 71 | unsigned char *in,*out,*iv; | ||
| 72 | |||
| 73 | in=(unsigned char *)input; | ||
| 74 | out=(unsigned char *)output; | ||
| 75 | iv=(unsigned char *)ivec; | ||
| 76 | |||
| 77 | if (enc) | ||
| 78 | { | ||
| 79 | c2l(iv,xor0); | ||
| 80 | c2l(iv,xor1); | ||
| 81 | for (; length>0; length-=8) | ||
| 82 | { | ||
| 83 | if (length >= 8) | ||
| 84 | { | ||
| 85 | c2l(in,sin0); | ||
| 86 | c2l(in,sin1); | ||
| 87 | } | ||
| 88 | else | ||
| 89 | c2ln(in,sin0,sin1,length); | ||
| 90 | tin[0]=sin0^xor0; | ||
| 91 | tin[1]=sin1^xor1; | ||
| 92 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 93 | tout0=tin[0]; | ||
| 94 | tout1=tin[1]; | ||
| 95 | xor0=sin0^tout0; | ||
| 96 | xor1=sin1^tout1; | ||
| 97 | l2c(tout0,out); | ||
| 98 | l2c(tout1,out); | ||
| 99 | } | ||
| 100 | } | ||
| 101 | else | ||
| 102 | { | ||
| 103 | c2l(iv,xor0); c2l(iv,xor1); | ||
| 104 | for (; length>0; length-=8) | ||
| 105 | { | ||
| 106 | c2l(in,sin0); | ||
| 107 | c2l(in,sin1); | ||
| 108 | tin[0]=sin0; | ||
| 109 | tin[1]=sin1; | ||
| 110 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 111 | tout0=tin[0]^xor0; | ||
| 112 | tout1=tin[1]^xor1; | ||
| 113 | if (length >= 8) | ||
| 114 | { | ||
| 115 | l2c(tout0,out); | ||
| 116 | l2c(tout1,out); | ||
| 117 | } | ||
| 118 | else | ||
| 119 | l2cn(tout0,tout1,out,length); | ||
| 120 | xor0=tout0^sin0; | ||
| 121 | xor1=tout1^sin1; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | tin[0]=tin[1]=0; | ||
| 125 | sin0=sin1=xor0=xor1=tout0=tout1=0; | ||
| 126 | } | ||
diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c new file mode 100644 index 0000000000..8526abf334 --- /dev/null +++ b/src/lib/libcrypto/des/qud_cksm.c | |||
| @@ -0,0 +1,144 @@ | |||
| 1 | /* crypto/des/qud_cksm.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* From "Message Authentication" R.R. Jueneman, S.M. Matyas, C.H. Meyer | ||
| 60 | * IEEE Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40 | ||
| 61 | * This module in only based on the code in this paper and is | ||
| 62 | * almost definitely not the same as the MIT implementation. | ||
| 63 | */ | ||
| 64 | #include "des_locl.h" | ||
| 65 | |||
| 66 | /* bug fix for dos - 7/6/91 - Larry hughes@logos.ucs.indiana.edu */ | ||
| 67 | #define Q_B0(a) (((DES_LONG)(a))) | ||
| 68 | #define Q_B1(a) (((DES_LONG)(a))<<8) | ||
| 69 | #define Q_B2(a) (((DES_LONG)(a))<<16) | ||
| 70 | #define Q_B3(a) (((DES_LONG)(a))<<24) | ||
| 71 | |||
| 72 | /* used to scramble things a bit */ | ||
| 73 | /* Got the value MIT uses via brute force :-) 2/10/90 eay */ | ||
| 74 | #define NOISE ((DES_LONG)83653421L) | ||
| 75 | |||
| 76 | DES_LONG des_quad_cksum(input, output, length, out_count, seed) | ||
| 77 | des_cblock (*input); | ||
| 78 | des_cblock (*output); | ||
| 79 | long length; | ||
| 80 | int out_count; | ||
| 81 | des_cblock (*seed); | ||
| 82 | { | ||
| 83 | DES_LONG z0,z1,t0,t1; | ||
| 84 | int i; | ||
| 85 | long l; | ||
| 86 | unsigned char *cp; | ||
| 87 | unsigned char *lp; | ||
| 88 | |||
| 89 | if (out_count < 1) out_count=1; | ||
| 90 | lp=(unsigned char *)output; | ||
| 91 | |||
| 92 | z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]); | ||
| 93 | z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]); | ||
| 94 | |||
| 95 | for (i=0; ((i<4)&&(i<out_count)); i++) | ||
| 96 | { | ||
| 97 | cp=(unsigned char *)input; | ||
| 98 | l=length; | ||
| 99 | while (l > 0) | ||
| 100 | { | ||
| 101 | if (l > 1) | ||
| 102 | { | ||
| 103 | t0= (DES_LONG)(*(cp++)); | ||
| 104 | t0|=(DES_LONG)Q_B1(*(cp++)); | ||
| 105 | l--; | ||
| 106 | } | ||
| 107 | else | ||
| 108 | t0= (DES_LONG)(*(cp++)); | ||
| 109 | l--; | ||
| 110 | /* add */ | ||
| 111 | t0+=z0; | ||
| 112 | t0&=0xffffffffL; | ||
| 113 | t1=z1; | ||
| 114 | /* square, well sort of square */ | ||
| 115 | z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL)) | ||
| 116 | &0xffffffffL)%0x7fffffffL; | ||
| 117 | z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL; | ||
| 118 | } | ||
| 119 | if (lp != NULL) | ||
| 120 | { | ||
| 121 | /* I believe I finally have things worked out. | ||
| 122 | * The MIT library assumes that the checksum | ||
| 123 | * is one huge number and it is returned in a | ||
| 124 | * host dependant byte order. | ||
| 125 | */ | ||
| 126 | static DES_LONG ltmp=1; | ||
| 127 | static unsigned char *c=(unsigned char *)<mp; | ||
| 128 | |||
| 129 | if (c[0]) | ||
| 130 | { | ||
| 131 | l2c(z0,lp); | ||
| 132 | l2c(z1,lp); | ||
| 133 | } | ||
| 134 | else | ||
| 135 | { | ||
| 136 | lp=output[out_count-i-1]; | ||
| 137 | l2n(z1,lp); | ||
| 138 | l2n(z0,lp); | ||
| 139 | } | ||
| 140 | } | ||
| 141 | } | ||
| 142 | return(z0); | ||
| 143 | } | ||
| 144 | |||
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c new file mode 100644 index 0000000000..8c30bd029a --- /dev/null +++ b/src/lib/libcrypto/des/rand_key.c | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | /* crypto/des/rand_key.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | #include <time.h> | ||
| 61 | |||
| 62 | static int seed=0; | ||
| 63 | static des_cblock init; | ||
| 64 | |||
| 65 | void des_random_seed(key) | ||
| 66 | des_cblock key; | ||
| 67 | { | ||
| 68 | memcpy(init,key,sizeof(des_cblock)); | ||
| 69 | seed=1; | ||
| 70 | } | ||
| 71 | |||
| 72 | void des_random_key(ret) | ||
| 73 | unsigned char *ret; | ||
| 74 | { | ||
| 75 | des_key_schedule ks; | ||
| 76 | static DES_LONG c=0; | ||
| 77 | static unsigned short pid=0; | ||
| 78 | static des_cblock data={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef}; | ||
| 79 | des_cblock key; | ||
| 80 | unsigned char *p; | ||
| 81 | DES_LONG t; | ||
| 82 | int i; | ||
| 83 | |||
| 84 | #ifdef MSDOS | ||
| 85 | pid=1; | ||
| 86 | #else | ||
| 87 | if (!pid) pid=getpid(); | ||
| 88 | #endif | ||
| 89 | p=key; | ||
| 90 | if (seed) | ||
| 91 | { | ||
| 92 | for (i=0; i<8; i++) | ||
| 93 | { | ||
| 94 | data[i] ^= init[i]; | ||
| 95 | init[i]=0; | ||
| 96 | } | ||
| 97 | seed=0; | ||
| 98 | } | ||
| 99 | t=(DES_LONG)time(NULL); | ||
| 100 | l2c(t,p); | ||
| 101 | t=(DES_LONG)((pid)|((c++)<<16)); | ||
| 102 | l2c(t,p); | ||
| 103 | |||
| 104 | des_set_odd_parity((des_cblock *)data); | ||
| 105 | des_set_key((des_cblock *)data,ks); | ||
| 106 | des_cbc_cksum((des_cblock *)key,(des_cblock *)key, | ||
| 107 | (long)sizeof(key),ks,(des_cblock *)data); | ||
| 108 | |||
| 109 | des_set_odd_parity((des_cblock *)key); | ||
| 110 | des_set_key((des_cblock *)key,ks); | ||
| 111 | des_cbc_cksum((des_cblock *)key,(des_cblock *)data, | ||
| 112 | (long)sizeof(key),ks,(des_cblock *)key); | ||
| 113 | |||
| 114 | memcpy(ret,data,sizeof(key)); | ||
| 115 | memset(key,0,sizeof(key)); | ||
| 116 | memset(ks,0,sizeof(ks)); | ||
| 117 | t=0; | ||
| 118 | } | ||
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c new file mode 100644 index 0000000000..c3bcd7ee2b --- /dev/null +++ b/src/lib/libcrypto/des/set_key.c | |||
| @@ -0,0 +1,246 @@ | |||
| 1 | /* crypto/des/set_key.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* set_key.c v 1.4 eay 24/9/91 | ||
| 60 | * 1.4 Speed up by 400% :-) | ||
| 61 | * 1.3 added register declarations. | ||
| 62 | * 1.2 unrolled make_key_sched a bit more | ||
| 63 | * 1.1 added norm_expand_bits | ||
| 64 | * 1.0 First working version | ||
| 65 | */ | ||
| 66 | #include "des_locl.h" | ||
| 67 | #include "podd.h" | ||
| 68 | #include "sk.h" | ||
| 69 | |||
| 70 | #ifndef NOPROTO | ||
| 71 | static int check_parity(des_cblock (*key)); | ||
| 72 | #else | ||
| 73 | static int check_parity(); | ||
| 74 | #endif | ||
| 75 | |||
| 76 | int des_check_key=0; | ||
| 77 | |||
| 78 | void des_set_odd_parity(key) | ||
| 79 | des_cblock (*key); | ||
| 80 | { | ||
| 81 | int i; | ||
| 82 | |||
| 83 | for (i=0; i<DES_KEY_SZ; i++) | ||
| 84 | (*key)[i]=odd_parity[(*key)[i]]; | ||
| 85 | } | ||
| 86 | |||
| 87 | static int check_parity(key) | ||
| 88 | des_cblock (*key); | ||
| 89 | { | ||
| 90 | int i; | ||
| 91 | |||
| 92 | for (i=0; i<DES_KEY_SZ; i++) | ||
| 93 | { | ||
| 94 | if ((*key)[i] != odd_parity[(*key)[i]]) | ||
| 95 | return(0); | ||
| 96 | } | ||
| 97 | return(1); | ||
| 98 | } | ||
| 99 | |||
| 100 | /* Weak and semi week keys as take from | ||
| 101 | * %A D.W. Davies | ||
| 102 | * %A W.L. Price | ||
| 103 | * %T Security for Computer Networks | ||
| 104 | * %I John Wiley & Sons | ||
| 105 | * %D 1984 | ||
| 106 | * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference | ||
| 107 | * (and actual cblock values). | ||
| 108 | */ | ||
| 109 | #define NUM_WEAK_KEY 16 | ||
| 110 | static des_cblock weak_keys[NUM_WEAK_KEY]={ | ||
| 111 | /* weak keys */ | ||
| 112 | {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, | ||
| 113 | {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, | ||
| 114 | {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, | ||
| 115 | {0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0}, | ||
| 116 | /* semi-weak keys */ | ||
| 117 | {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE}, | ||
| 118 | {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01}, | ||
| 119 | {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1}, | ||
| 120 | {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E}, | ||
| 121 | {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1}, | ||
| 122 | {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01}, | ||
| 123 | {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE}, | ||
| 124 | {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E}, | ||
| 125 | {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E}, | ||
| 126 | {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01}, | ||
| 127 | {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, | ||
| 128 | {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}}; | ||
| 129 | |||
| 130 | int des_is_weak_key(key) | ||
| 131 | des_cblock (*key); | ||
| 132 | { | ||
| 133 | int i; | ||
| 134 | |||
| 135 | for (i=0; i<NUM_WEAK_KEY; i++) | ||
| 136 | /* Added == 0 to comparision, I obviously don't run | ||
| 137 | * this section very often :-(, thanks to | ||
| 138 | * engineering@MorningStar.Com for the fix | ||
| 139 | * eay 93/06/29 | ||
| 140 | * Another problem, I was comparing only the first 4 | ||
| 141 | * bytes, 97/03/18 */ | ||
| 142 | if (memcmp(weak_keys[i],key,sizeof(des_cblock)) == 0) return(1); | ||
| 143 | return(0); | ||
| 144 | } | ||
| 145 | |||
| 146 | /* NOW DEFINED IN des_local.h | ||
| 147 | * See ecb_encrypt.c for a pseudo description of these macros. | ||
| 148 | * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ | ||
| 149 | * (b)^=(t),\ | ||
| 150 | * (a)=((a)^((t)<<(n)))) | ||
| 151 | */ | ||
| 152 | |||
| 153 | #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ | ||
| 154 | (a)=(a)^(t)^(t>>(16-(n)))) | ||
| 155 | |||
| 156 | /* return 0 if key parity is odd (correct), | ||
| 157 | * return -1 if key parity error, | ||
| 158 | * return -2 if illegal weak key. | ||
| 159 | */ | ||
| 160 | int des_set_key(key, schedule) | ||
| 161 | des_cblock (*key); | ||
| 162 | des_key_schedule schedule; | ||
| 163 | { | ||
| 164 | static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; | ||
| 165 | register DES_LONG c,d,t,s,t2; | ||
| 166 | register unsigned char *in; | ||
| 167 | register DES_LONG *k; | ||
| 168 | register int i; | ||
| 169 | |||
| 170 | if (des_check_key) | ||
| 171 | { | ||
| 172 | if (!check_parity(key)) | ||
| 173 | return(-1); | ||
| 174 | |||
| 175 | if (des_is_weak_key(key)) | ||
| 176 | return(-2); | ||
| 177 | } | ||
| 178 | |||
| 179 | k=(DES_LONG *)schedule; | ||
| 180 | in=(unsigned char *)key; | ||
| 181 | |||
| 182 | c2l(in,c); | ||
| 183 | c2l(in,d); | ||
| 184 | |||
| 185 | /* do PC1 in 60 simple operations */ | ||
| 186 | /* PERM_OP(d,c,t,4,0x0f0f0f0fL); | ||
| 187 | HPERM_OP(c,t,-2, 0xcccc0000L); | ||
| 188 | HPERM_OP(c,t,-1, 0xaaaa0000L); | ||
| 189 | HPERM_OP(c,t, 8, 0x00ff0000L); | ||
| 190 | HPERM_OP(c,t,-1, 0xaaaa0000L); | ||
| 191 | HPERM_OP(d,t,-8, 0xff000000L); | ||
| 192 | HPERM_OP(d,t, 8, 0x00ff0000L); | ||
| 193 | HPERM_OP(d,t, 2, 0x33330000L); | ||
| 194 | d=((d&0x00aa00aaL)<<7L)|((d&0x55005500L)>>7L)|(d&0xaa55aa55L); | ||
| 195 | d=(d>>8)|((c&0xf0000000L)>>4); | ||
| 196 | c&=0x0fffffffL; */ | ||
| 197 | |||
| 198 | /* I now do it in 47 simple operations :-) | ||
| 199 | * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov) | ||
| 200 | * for the inspiration. :-) */ | ||
| 201 | PERM_OP (d,c,t,4,0x0f0f0f0fL); | ||
| 202 | HPERM_OP(c,t,-2,0xcccc0000L); | ||
| 203 | HPERM_OP(d,t,-2,0xcccc0000L); | ||
| 204 | PERM_OP (d,c,t,1,0x55555555L); | ||
| 205 | PERM_OP (c,d,t,8,0x00ff00ffL); | ||
| 206 | PERM_OP (d,c,t,1,0x55555555L); | ||
| 207 | d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) | | ||
| 208 | ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L)); | ||
| 209 | c&=0x0fffffffL; | ||
| 210 | |||
| 211 | for (i=0; i<ITERATIONS; i++) | ||
| 212 | { | ||
| 213 | if (shifts2[i]) | ||
| 214 | { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); } | ||
| 215 | else | ||
| 216 | { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); } | ||
| 217 | c&=0x0fffffffL; | ||
| 218 | d&=0x0fffffffL; | ||
| 219 | /* could be a few less shifts but I am to lazy at this | ||
| 220 | * point in time to investigate */ | ||
| 221 | s= des_skb[0][ (c )&0x3f ]| | ||
| 222 | des_skb[1][((c>> 6)&0x03)|((c>> 7L)&0x3c)]| | ||
| 223 | des_skb[2][((c>>13)&0x0f)|((c>>14L)&0x30)]| | ||
| 224 | des_skb[3][((c>>20)&0x01)|((c>>21L)&0x06) | | ||
| 225 | ((c>>22L)&0x38)]; | ||
| 226 | t= des_skb[4][ (d )&0x3f ]| | ||
| 227 | des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]| | ||
| 228 | des_skb[6][ (d>>15L)&0x3f ]| | ||
| 229 | des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)]; | ||
| 230 | |||
| 231 | /* table contained 0213 4657 */ | ||
| 232 | t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL; | ||
| 233 | *(k++)=ROTATE(t2,30)&0xffffffffL; | ||
| 234 | |||
| 235 | t2=((s>>16L)|(t&0xffff0000L)); | ||
| 236 | *(k++)=ROTATE(t2,26)&0xffffffffL; | ||
| 237 | } | ||
| 238 | return(0); | ||
| 239 | } | ||
| 240 | |||
| 241 | int des_key_sched(key, schedule) | ||
| 242 | des_cblock (*key); | ||
| 243 | des_key_schedule schedule; | ||
| 244 | { | ||
| 245 | return(des_set_key(key,schedule)); | ||
| 246 | } | ||
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h new file mode 100644 index 0000000000..81813f9f7a --- /dev/null +++ b/src/lib/libcrypto/des/spr.h | |||
| @@ -0,0 +1,204 @@ | |||
| 1 | /* crypto/des/spr.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | const DES_LONG des_SPtrans[8][64]={ | ||
| 60 | { | ||
| 61 | /* nibble 0 */ | ||
| 62 | 0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L, | ||
| 63 | 0x02000000L, 0x00080802L, 0x00080002L, 0x02000002L, | ||
| 64 | 0x00080802L, 0x02080800L, 0x02080000L, 0x00000802L, | ||
| 65 | 0x02000802L, 0x02000000L, 0x00000000L, 0x00080002L, | ||
| 66 | 0x00080000L, 0x00000002L, 0x02000800L, 0x00080800L, | ||
| 67 | 0x02080802L, 0x02080000L, 0x00000802L, 0x02000800L, | ||
| 68 | 0x00000002L, 0x00000800L, 0x00080800L, 0x02080002L, | ||
| 69 | 0x00000800L, 0x02000802L, 0x02080002L, 0x00000000L, | ||
| 70 | 0x00000000L, 0x02080802L, 0x02000800L, 0x00080002L, | ||
| 71 | 0x02080800L, 0x00080000L, 0x00000802L, 0x02000800L, | ||
| 72 | 0x02080002L, 0x00000800L, 0x00080800L, 0x02000002L, | ||
| 73 | 0x00080802L, 0x00000002L, 0x02000002L, 0x02080000L, | ||
| 74 | 0x02080802L, 0x00080800L, 0x02080000L, 0x02000802L, | ||
| 75 | 0x02000000L, 0x00000802L, 0x00080002L, 0x00000000L, | ||
| 76 | 0x00080000L, 0x02000000L, 0x02000802L, 0x02080800L, | ||
| 77 | 0x00000002L, 0x02080002L, 0x00000800L, 0x00080802L, | ||
| 78 | },{ | ||
| 79 | /* nibble 1 */ | ||
| 80 | 0x40108010L, 0x00000000L, 0x00108000L, 0x40100000L, | ||
| 81 | 0x40000010L, 0x00008010L, 0x40008000L, 0x00108000L, | ||
| 82 | 0x00008000L, 0x40100010L, 0x00000010L, 0x40008000L, | ||
| 83 | 0x00100010L, 0x40108000L, 0x40100000L, 0x00000010L, | ||
| 84 | 0x00100000L, 0x40008010L, 0x40100010L, 0x00008000L, | ||
| 85 | 0x00108010L, 0x40000000L, 0x00000000L, 0x00100010L, | ||
| 86 | 0x40008010L, 0x00108010L, 0x40108000L, 0x40000010L, | ||
| 87 | 0x40000000L, 0x00100000L, 0x00008010L, 0x40108010L, | ||
| 88 | 0x00100010L, 0x40108000L, 0x40008000L, 0x00108010L, | ||
| 89 | 0x40108010L, 0x00100010L, 0x40000010L, 0x00000000L, | ||
| 90 | 0x40000000L, 0x00008010L, 0x00100000L, 0x40100010L, | ||
| 91 | 0x00008000L, 0x40000000L, 0x00108010L, 0x40008010L, | ||
| 92 | 0x40108000L, 0x00008000L, 0x00000000L, 0x40000010L, | ||
| 93 | 0x00000010L, 0x40108010L, 0x00108000L, 0x40100000L, | ||
| 94 | 0x40100010L, 0x00100000L, 0x00008010L, 0x40008000L, | ||
| 95 | 0x40008010L, 0x00000010L, 0x40100000L, 0x00108000L, | ||
| 96 | },{ | ||
| 97 | /* nibble 2 */ | ||
| 98 | 0x04000001L, 0x04040100L, 0x00000100L, 0x04000101L, | ||
| 99 | 0x00040001L, 0x04000000L, 0x04000101L, 0x00040100L, | ||
| 100 | 0x04000100L, 0x00040000L, 0x04040000L, 0x00000001L, | ||
| 101 | 0x04040101L, 0x00000101L, 0x00000001L, 0x04040001L, | ||
| 102 | 0x00000000L, 0x00040001L, 0x04040100L, 0x00000100L, | ||
| 103 | 0x00000101L, 0x04040101L, 0x00040000L, 0x04000001L, | ||
| 104 | 0x04040001L, 0x04000100L, 0x00040101L, 0x04040000L, | ||
| 105 | 0x00040100L, 0x00000000L, 0x04000000L, 0x00040101L, | ||
| 106 | 0x04040100L, 0x00000100L, 0x00000001L, 0x00040000L, | ||
| 107 | 0x00000101L, 0x00040001L, 0x04040000L, 0x04000101L, | ||
| 108 | 0x00000000L, 0x04040100L, 0x00040100L, 0x04040001L, | ||
| 109 | 0x00040001L, 0x04000000L, 0x04040101L, 0x00000001L, | ||
| 110 | 0x00040101L, 0x04000001L, 0x04000000L, 0x04040101L, | ||
| 111 | 0x00040000L, 0x04000100L, 0x04000101L, 0x00040100L, | ||
| 112 | 0x04000100L, 0x00000000L, 0x04040001L, 0x00000101L, | ||
| 113 | 0x04000001L, 0x00040101L, 0x00000100L, 0x04040000L, | ||
| 114 | },{ | ||
| 115 | /* nibble 3 */ | ||
| 116 | 0x00401008L, 0x10001000L, 0x00000008L, 0x10401008L, | ||
| 117 | 0x00000000L, 0x10400000L, 0x10001008L, 0x00400008L, | ||
| 118 | 0x10401000L, 0x10000008L, 0x10000000L, 0x00001008L, | ||
| 119 | 0x10000008L, 0x00401008L, 0x00400000L, 0x10000000L, | ||
| 120 | 0x10400008L, 0x00401000L, 0x00001000L, 0x00000008L, | ||
| 121 | 0x00401000L, 0x10001008L, 0x10400000L, 0x00001000L, | ||
| 122 | 0x00001008L, 0x00000000L, 0x00400008L, 0x10401000L, | ||
| 123 | 0x10001000L, 0x10400008L, 0x10401008L, 0x00400000L, | ||
| 124 | 0x10400008L, 0x00001008L, 0x00400000L, 0x10000008L, | ||
| 125 | 0x00401000L, 0x10001000L, 0x00000008L, 0x10400000L, | ||
| 126 | 0x10001008L, 0x00000000L, 0x00001000L, 0x00400008L, | ||
| 127 | 0x00000000L, 0x10400008L, 0x10401000L, 0x00001000L, | ||
| 128 | 0x10000000L, 0x10401008L, 0x00401008L, 0x00400000L, | ||
| 129 | 0x10401008L, 0x00000008L, 0x10001000L, 0x00401008L, | ||
| 130 | 0x00400008L, 0x00401000L, 0x10400000L, 0x10001008L, | ||
| 131 | 0x00001008L, 0x10000000L, 0x10000008L, 0x10401000L, | ||
| 132 | },{ | ||
| 133 | /* nibble 4 */ | ||
| 134 | 0x08000000L, 0x00010000L, 0x00000400L, 0x08010420L, | ||
| 135 | 0x08010020L, 0x08000400L, 0x00010420L, 0x08010000L, | ||
| 136 | 0x00010000L, 0x00000020L, 0x08000020L, 0x00010400L, | ||
| 137 | 0x08000420L, 0x08010020L, 0x08010400L, 0x00000000L, | ||
| 138 | 0x00010400L, 0x08000000L, 0x00010020L, 0x00000420L, | ||
| 139 | 0x08000400L, 0x00010420L, 0x00000000L, 0x08000020L, | ||
| 140 | 0x00000020L, 0x08000420L, 0x08010420L, 0x00010020L, | ||
| 141 | 0x08010000L, 0x00000400L, 0x00000420L, 0x08010400L, | ||
| 142 | 0x08010400L, 0x08000420L, 0x00010020L, 0x08010000L, | ||
| 143 | 0x00010000L, 0x00000020L, 0x08000020L, 0x08000400L, | ||
| 144 | 0x08000000L, 0x00010400L, 0x08010420L, 0x00000000L, | ||
| 145 | 0x00010420L, 0x08000000L, 0x00000400L, 0x00010020L, | ||
| 146 | 0x08000420L, 0x00000400L, 0x00000000L, 0x08010420L, | ||
| 147 | 0x08010020L, 0x08010400L, 0x00000420L, 0x00010000L, | ||
| 148 | 0x00010400L, 0x08010020L, 0x08000400L, 0x00000420L, | ||
| 149 | 0x00000020L, 0x00010420L, 0x08010000L, 0x08000020L, | ||
| 150 | },{ | ||
| 151 | /* nibble 5 */ | ||
| 152 | 0x80000040L, 0x00200040L, 0x00000000L, 0x80202000L, | ||
| 153 | 0x00200040L, 0x00002000L, 0x80002040L, 0x00200000L, | ||
| 154 | 0x00002040L, 0x80202040L, 0x00202000L, 0x80000000L, | ||
| 155 | 0x80002000L, 0x80000040L, 0x80200000L, 0x00202040L, | ||
| 156 | 0x00200000L, 0x80002040L, 0x80200040L, 0x00000000L, | ||
| 157 | 0x00002000L, 0x00000040L, 0x80202000L, 0x80200040L, | ||
| 158 | 0x80202040L, 0x80200000L, 0x80000000L, 0x00002040L, | ||
| 159 | 0x00000040L, 0x00202000L, 0x00202040L, 0x80002000L, | ||
| 160 | 0x00002040L, 0x80000000L, 0x80002000L, 0x00202040L, | ||
| 161 | 0x80202000L, 0x00200040L, 0x00000000L, 0x80002000L, | ||
| 162 | 0x80000000L, 0x00002000L, 0x80200040L, 0x00200000L, | ||
| 163 | 0x00200040L, 0x80202040L, 0x00202000L, 0x00000040L, | ||
| 164 | 0x80202040L, 0x00202000L, 0x00200000L, 0x80002040L, | ||
| 165 | 0x80000040L, 0x80200000L, 0x00202040L, 0x00000000L, | ||
| 166 | 0x00002000L, 0x80000040L, 0x80002040L, 0x80202000L, | ||
| 167 | 0x80200000L, 0x00002040L, 0x00000040L, 0x80200040L, | ||
| 168 | },{ | ||
| 169 | /* nibble 6 */ | ||
| 170 | 0x00004000L, 0x00000200L, 0x01000200L, 0x01000004L, | ||
| 171 | 0x01004204L, 0x00004004L, 0x00004200L, 0x00000000L, | ||
| 172 | 0x01000000L, 0x01000204L, 0x00000204L, 0x01004000L, | ||
| 173 | 0x00000004L, 0x01004200L, 0x01004000L, 0x00000204L, | ||
| 174 | 0x01000204L, 0x00004000L, 0x00004004L, 0x01004204L, | ||
| 175 | 0x00000000L, 0x01000200L, 0x01000004L, 0x00004200L, | ||
| 176 | 0x01004004L, 0x00004204L, 0x01004200L, 0x00000004L, | ||
| 177 | 0x00004204L, 0x01004004L, 0x00000200L, 0x01000000L, | ||
| 178 | 0x00004204L, 0x01004000L, 0x01004004L, 0x00000204L, | ||
| 179 | 0x00004000L, 0x00000200L, 0x01000000L, 0x01004004L, | ||
| 180 | 0x01000204L, 0x00004204L, 0x00004200L, 0x00000000L, | ||
| 181 | 0x00000200L, 0x01000004L, 0x00000004L, 0x01000200L, | ||
| 182 | 0x00000000L, 0x01000204L, 0x01000200L, 0x00004200L, | ||
| 183 | 0x00000204L, 0x00004000L, 0x01004204L, 0x01000000L, | ||
| 184 | 0x01004200L, 0x00000004L, 0x00004004L, 0x01004204L, | ||
| 185 | 0x01000004L, 0x01004200L, 0x01004000L, 0x00004004L, | ||
| 186 | },{ | ||
| 187 | /* nibble 7 */ | ||
| 188 | 0x20800080L, 0x20820000L, 0x00020080L, 0x00000000L, | ||
| 189 | 0x20020000L, 0x00800080L, 0x20800000L, 0x20820080L, | ||
| 190 | 0x00000080L, 0x20000000L, 0x00820000L, 0x00020080L, | ||
| 191 | 0x00820080L, 0x20020080L, 0x20000080L, 0x20800000L, | ||
| 192 | 0x00020000L, 0x00820080L, 0x00800080L, 0x20020000L, | ||
| 193 | 0x20820080L, 0x20000080L, 0x00000000L, 0x00820000L, | ||
| 194 | 0x20000000L, 0x00800000L, 0x20020080L, 0x20800080L, | ||
| 195 | 0x00800000L, 0x00020000L, 0x20820000L, 0x00000080L, | ||
| 196 | 0x00800000L, 0x00020000L, 0x20000080L, 0x20820080L, | ||
| 197 | 0x00020080L, 0x20000000L, 0x00000000L, 0x00820000L, | ||
| 198 | 0x20800080L, 0x20020080L, 0x20020000L, 0x00800080L, | ||
| 199 | 0x20820000L, 0x00000080L, 0x00800080L, 0x20020000L, | ||
| 200 | 0x20820080L, 0x00800000L, 0x20800000L, 0x20000080L, | ||
| 201 | 0x00820000L, 0x00020080L, 0x20020080L, 0x20800000L, | ||
| 202 | 0x00000080L, 0x20820000L, 0x00820080L, 0x00000000L, | ||
| 203 | 0x20000000L, 0x20800080L, 0x00020000L, 0x00820080L, | ||
| 204 | }}; | ||
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c new file mode 100644 index 0000000000..3365c1bcf3 --- /dev/null +++ b/src/lib/libcrypto/des/str2key.c | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | /* crypto/des/str2key.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | extern int des_check_key; | ||
| 62 | |||
| 63 | void des_string_to_key(str, key) | ||
| 64 | char *str; | ||
| 65 | des_cblock (*key); | ||
| 66 | { | ||
| 67 | des_key_schedule ks; | ||
| 68 | int i,length; | ||
| 69 | register unsigned char j; | ||
| 70 | |||
| 71 | memset(key,0,8); | ||
| 72 | length=strlen(str); | ||
| 73 | #ifdef OLD_STR_TO_KEY | ||
| 74 | for (i=0; i<length; i++) | ||
| 75 | (*key)[i%8]^=(str[i]<<1); | ||
| 76 | #else /* MIT COMPATIBLE */ | ||
| 77 | for (i=0; i<length; i++) | ||
| 78 | { | ||
| 79 | j=str[i]; | ||
| 80 | if ((i%16) < 8) | ||
| 81 | (*key)[i%8]^=(j<<1); | ||
| 82 | else | ||
| 83 | { | ||
| 84 | /* Reverse the bit order 05/05/92 eay */ | ||
| 85 | j=((j<<4)&0xf0)|((j>>4)&0x0f); | ||
| 86 | j=((j<<2)&0xcc)|((j>>2)&0x33); | ||
| 87 | j=((j<<1)&0xaa)|((j>>1)&0x55); | ||
| 88 | (*key)[7-(i%8)]^=j; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | des_set_odd_parity((des_cblock *)key); | ||
| 93 | i=des_check_key; | ||
| 94 | des_check_key=0; | ||
| 95 | des_set_key((des_cblock *)key,ks); | ||
| 96 | des_check_key=i; | ||
| 97 | des_cbc_cksum((des_cblock *)str,(des_cblock *)key,(long)length,ks, | ||
| 98 | (des_cblock *)key); | ||
| 99 | memset(ks,0,sizeof(ks)); | ||
| 100 | des_set_odd_parity((des_cblock *)key); | ||
| 101 | } | ||
| 102 | |||
| 103 | void des_string_to_2keys(str, key1, key2) | ||
| 104 | char *str; | ||
| 105 | des_cblock (*key1); | ||
| 106 | des_cblock (*key2); | ||
| 107 | { | ||
| 108 | des_key_schedule ks; | ||
| 109 | int i,length; | ||
| 110 | register unsigned char j; | ||
| 111 | |||
| 112 | memset(key1,0,8); | ||
| 113 | memset(key2,0,8); | ||
| 114 | length=strlen(str); | ||
| 115 | #ifdef OLD_STR_TO_KEY | ||
| 116 | if (length <= 8) | ||
| 117 | { | ||
| 118 | for (i=0; i<length; i++) | ||
| 119 | { | ||
| 120 | (*key2)[i]=(*key1)[i]=(str[i]<<1); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | else | ||
| 124 | { | ||
| 125 | for (i=0; i<length; i++) | ||
| 126 | { | ||
| 127 | if ((i/8)&1) | ||
| 128 | (*key2)[i%8]^=(str[i]<<1); | ||
| 129 | else | ||
| 130 | (*key1)[i%8]^=(str[i]<<1); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | #else /* MIT COMPATIBLE */ | ||
| 134 | for (i=0; i<length; i++) | ||
| 135 | { | ||
| 136 | j=str[i]; | ||
| 137 | if ((i%32) < 16) | ||
| 138 | { | ||
| 139 | if ((i%16) < 8) | ||
| 140 | (*key1)[i%8]^=(j<<1); | ||
| 141 | else | ||
| 142 | (*key2)[i%8]^=(j<<1); | ||
| 143 | } | ||
| 144 | else | ||
| 145 | { | ||
| 146 | j=((j<<4)&0xf0)|((j>>4)&0x0f); | ||
| 147 | j=((j<<2)&0xcc)|((j>>2)&0x33); | ||
| 148 | j=((j<<1)&0xaa)|((j>>1)&0x55); | ||
| 149 | if ((i%16) < 8) | ||
| 150 | (*key1)[7-(i%8)]^=j; | ||
| 151 | else | ||
| 152 | (*key2)[7-(i%8)]^=j; | ||
| 153 | } | ||
| 154 | } | ||
| 155 | if (length <= 8) memcpy(key2,key1,8); | ||
| 156 | #endif | ||
| 157 | des_set_odd_parity((des_cblock *)key1); | ||
| 158 | des_set_odd_parity((des_cblock *)key2); | ||
| 159 | i=des_check_key; | ||
| 160 | des_check_key=0; | ||
| 161 | des_set_key((des_cblock *)key1,ks); | ||
| 162 | des_cbc_cksum((des_cblock *)str,(des_cblock *)key1,(long)length,ks, | ||
| 163 | (des_cblock *)key1); | ||
| 164 | des_set_key((des_cblock *)key2,ks); | ||
| 165 | des_cbc_cksum((des_cblock *)str,(des_cblock *)key2,(long)length,ks, | ||
| 166 | (des_cblock *)key2); | ||
| 167 | des_check_key=i; | ||
| 168 | memset(ks,0,sizeof(ks)); | ||
| 169 | des_set_odd_parity(key1); | ||
| 170 | des_set_odd_parity(key2); | ||
| 171 | } | ||
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c new file mode 100644 index 0000000000..031589bf50 --- /dev/null +++ b/src/lib/libcrypto/des/xcbc_enc.c | |||
| @@ -0,0 +1,206 @@ | |||
| 1 | /* crypto/des/xcbc_enc.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include "des_locl.h" | ||
| 60 | |||
| 61 | /* RSA's DESX */ | ||
| 62 | |||
| 63 | static unsigned char desx_white_in2out[256]={ | ||
| 64 | 0xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0, | ||
| 65 | 0x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A, | ||
| 66 | 0x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36, | ||
| 67 | 0x3E,0xEE,0xFB,0x95,0x1A,0xFE,0xCE,0xA8,0x34,0xA9,0x13,0xF0,0xA6,0x3F,0xD8,0x0C, | ||
| 68 | 0x78,0x24,0xAF,0x23,0x52,0xC1,0x67,0x17,0xF5,0x66,0x90,0xE7,0xE8,0x07,0xB8,0x60, | ||
| 69 | 0x48,0xE6,0x1E,0x53,0xF3,0x92,0xA4,0x72,0x8C,0x08,0x15,0x6E,0x86,0x00,0x84,0xFA, | ||
| 70 | 0xF4,0x7F,0x8A,0x42,0x19,0xF6,0xDB,0xCD,0x14,0x8D,0x50,0x12,0xBA,0x3C,0x06,0x4E, | ||
| 71 | 0xEC,0xB3,0x35,0x11,0xA1,0x88,0x8E,0x2B,0x94,0x99,0xB7,0x71,0x74,0xD3,0xE4,0xBF, | ||
| 72 | 0x3A,0xDE,0x96,0x0E,0xBC,0x0A,0xED,0x77,0xFC,0x37,0x6B,0x03,0x79,0x89,0x62,0xC6, | ||
| 73 | 0xD7,0xC0,0xD2,0x7C,0x6A,0x8B,0x22,0xA3,0x5B,0x05,0x5D,0x02,0x75,0xD5,0x61,0xE3, | ||
| 74 | 0x18,0x8F,0x55,0x51,0xAD,0x1F,0x0B,0x5E,0x85,0xE5,0xC2,0x57,0x63,0xCA,0x3D,0x6C, | ||
| 75 | 0xB4,0xC5,0xCC,0x70,0xB2,0x91,0x59,0x0D,0x47,0x20,0xC8,0x4F,0x58,0xE0,0x01,0xE2, | ||
| 76 | 0x16,0x38,0xC4,0x6F,0x3B,0x0F,0x65,0x46,0xBE,0x7E,0x2D,0x7B,0x82,0xF9,0x40,0xB5, | ||
| 77 | 0x1D,0x73,0xF8,0xEB,0x26,0xC7,0x87,0x97,0x25,0x54,0xB1,0x28,0xAA,0x98,0x9D,0xA5, | ||
| 78 | 0x64,0x6D,0x7A,0xD4,0x10,0x81,0x44,0xEF,0x49,0xD6,0xAE,0x2E,0xDD,0x76,0x5C,0x2F, | ||
| 79 | 0xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB, | ||
| 80 | }; | ||
| 81 | |||
| 82 | void des_xwhite_in2out(des_key,in_white,out_white) | ||
| 83 | des_cblock (*des_key); | ||
| 84 | des_cblock (*in_white); | ||
| 85 | des_cblock (*out_white); | ||
| 86 | { | ||
| 87 | unsigned char *key,*in,*out; | ||
| 88 | int out0,out1; | ||
| 89 | int i; | ||
| 90 | |||
| 91 | key=(unsigned char *)des_key; | ||
| 92 | in=(unsigned char *)in_white; | ||
| 93 | out=(unsigned char *)out_white; | ||
| 94 | |||
| 95 | out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0; | ||
| 96 | out0=out1=0; | ||
| 97 | for (i=0; i<8; i++) | ||
| 98 | { | ||
| 99 | out[i]=key[i]^desx_white_in2out[out0^out1]; | ||
| 100 | out0=out1; | ||
| 101 | out1=(int)out[i&0x07]; | ||
| 102 | } | ||
| 103 | |||
| 104 | out0=out[0]; | ||
| 105 | out1=out[i]; | ||
| 106 | for (i=0; i<8; i++) | ||
| 107 | { | ||
| 108 | out[i]=in[i]^desx_white_in2out[out0^out1]; | ||
| 109 | out0=out1; | ||
| 110 | out1=(int)out[i&0x07]; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | void des_xcbc_encrypt(input, output, length, schedule, ivec, inw,outw,enc) | ||
| 115 | des_cblock (*input); | ||
| 116 | des_cblock (*output); | ||
| 117 | long length; | ||
| 118 | des_key_schedule schedule; | ||
| 119 | des_cblock (*ivec); | ||
| 120 | des_cblock (*inw); | ||
| 121 | des_cblock (*outw); | ||
| 122 | int enc; | ||
| 123 | { | ||
| 124 | register DES_LONG tin0,tin1; | ||
| 125 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 126 | register DES_LONG inW0,inW1,outW0,outW1; | ||
| 127 | register unsigned char *in,*out; | ||
| 128 | register long l=length; | ||
| 129 | DES_LONG tin[2]; | ||
| 130 | unsigned char *iv; | ||
| 131 | |||
| 132 | in=(unsigned char *)inw; | ||
| 133 | c2l(in,inW0); | ||
| 134 | c2l(in,inW1); | ||
| 135 | in=(unsigned char *)outw; | ||
| 136 | c2l(in,outW0); | ||
| 137 | c2l(in,outW1); | ||
| 138 | |||
| 139 | in=(unsigned char *)input; | ||
| 140 | out=(unsigned char *)output; | ||
| 141 | iv=(unsigned char *)ivec; | ||
| 142 | |||
| 143 | if (enc) | ||
| 144 | { | ||
| 145 | c2l(iv,tout0); | ||
| 146 | c2l(iv,tout1); | ||
| 147 | for (l-=8; l>=0; l-=8) | ||
| 148 | { | ||
| 149 | c2l(in,tin0); | ||
| 150 | c2l(in,tin1); | ||
| 151 | tin0^=tout0^inW0; tin[0]=tin0; | ||
| 152 | tin1^=tout1^inW1; tin[1]=tin1; | ||
| 153 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 154 | tout0=tin[0]^outW0; l2c(tout0,out); | ||
| 155 | tout1=tin[1]^outW1; l2c(tout1,out); | ||
| 156 | } | ||
| 157 | if (l != -8) | ||
| 158 | { | ||
| 159 | c2ln(in,tin0,tin1,l+8); | ||
| 160 | tin0^=tout0^inW0; tin[0]=tin0; | ||
| 161 | tin1^=tout1^inW1; tin[1]=tin1; | ||
| 162 | des_encrypt((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 163 | tout0=tin[0]^outW0; l2c(tout0,out); | ||
| 164 | tout1=tin[1]^outW1; l2c(tout1,out); | ||
| 165 | } | ||
| 166 | iv=(unsigned char *)ivec; | ||
| 167 | l2c(tout0,iv); | ||
| 168 | l2c(tout1,iv); | ||
| 169 | } | ||
| 170 | else | ||
| 171 | { | ||
| 172 | c2l(iv,xor0); | ||
| 173 | c2l(iv,xor1); | ||
| 174 | for (l-=8; l>0; l-=8) | ||
| 175 | { | ||
| 176 | c2l(in,tin0); tin[0]=tin0^outW0; | ||
| 177 | c2l(in,tin1); tin[1]=tin1^outW1; | ||
| 178 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 179 | tout0=tin[0]^xor0^inW0; | ||
| 180 | tout1=tin[1]^xor1^inW1; | ||
| 181 | l2c(tout0,out); | ||
| 182 | l2c(tout1,out); | ||
| 183 | xor0=tin0; | ||
| 184 | xor1=tin1; | ||
| 185 | } | ||
| 186 | if (l != -8) | ||
| 187 | { | ||
| 188 | c2l(in,tin0); tin[0]=tin0^outW0; | ||
| 189 | c2l(in,tin1); tin[1]=tin1^outW1; | ||
| 190 | des_encrypt((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 191 | tout0=tin[0]^xor0^inW0; | ||
| 192 | tout1=tin[1]^xor1^inW1; | ||
| 193 | l2cn(tout0,tout1,out,l+8); | ||
| 194 | xor0=tin0; | ||
| 195 | xor1=tin1; | ||
| 196 | } | ||
| 197 | |||
| 198 | iv=(unsigned char *)ivec; | ||
| 199 | l2c(xor0,iv); | ||
| 200 | l2c(xor1,iv); | ||
| 201 | } | ||
| 202 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 203 | inW0=inW1=outW0=outW1=0; | ||
| 204 | tin[0]=tin[1]=0; | ||
| 205 | } | ||
| 206 | |||
