diff options
author | jsing <> | 2014-05-08 13:20:49 +0000 |
---|---|---|
committer | jsing <> | 2014-05-08 13:20:49 +0000 |
commit | 2e8879604fe3abbc2431ca79a4a923f1e87da75e (patch) | |
tree | 18398455223278c0cb2bd44f57e4499a4370f665 /src/lib/libcrypto/bn/bn_mpi.c | |
parent | f7d9a959949e5f3918c1cf2b27fb4cd7b62d07d5 (diff) | |
download | openbsd-2e8879604fe3abbc2431ca79a4a923f1e87da75e.tar.gz openbsd-2e8879604fe3abbc2431ca79a4a923f1e87da75e.tar.bz2 openbsd-2e8879604fe3abbc2431ca79a4a923f1e87da75e.zip |
Emergency knfectomie requested by tedu@.
Diffstat (limited to 'src/lib/libcrypto/bn/bn_mpi.c')
-rw-r--r-- | src/lib/libcrypto/bn/bn_mpi.c | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c index a054d21aed..64974d8ed3 100644 --- a/src/lib/libcrypto/bn/bn_mpi.c +++ b/src/lib/libcrypto/bn/bn_mpi.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 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 | 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 | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 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. | 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 | 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. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 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: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 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 | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -60,71 +60,71 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "bn_lcl.h" | 61 | #include "bn_lcl.h" |
62 | 62 | ||
63 | int BN_bn2mpi(const BIGNUM *a, unsigned char *d) | 63 | int |
64 | { | 64 | BN_bn2mpi(const BIGNUM *a, unsigned char *d) |
65 | { | ||
65 | int bits; | 66 | int bits; |
66 | int num=0; | 67 | int num = 0; |
67 | int ext=0; | 68 | int ext = 0; |
68 | long l; | 69 | long l; |
69 | 70 | ||
70 | bits=BN_num_bits(a); | 71 | bits = BN_num_bits(a); |
71 | num=(bits+7)/8; | 72 | num = (bits + 7) / 8; |
72 | if (bits > 0) | 73 | if (bits > 0) { |
73 | { | 74 | ext = ((bits & 0x07) == 0); |
74 | ext=((bits & 0x07) == 0); | 75 | } |
75 | } | ||
76 | if (d == NULL) | 76 | if (d == NULL) |
77 | return(num+4+ext); | 77 | return (num + 4 + ext); |
78 | 78 | ||
79 | l=num+ext; | 79 | l = num + ext; |
80 | d[0]=(unsigned char)(l>>24)&0xff; | 80 | d[0] = (unsigned char)(l >> 24) & 0xff; |
81 | d[1]=(unsigned char)(l>>16)&0xff; | 81 | d[1] = (unsigned char)(l >> 16) & 0xff; |
82 | d[2]=(unsigned char)(l>> 8)&0xff; | 82 | d[2] = (unsigned char)(l >> 8) & 0xff; |
83 | d[3]=(unsigned char)(l )&0xff; | 83 | d[3] = (unsigned char)(l) & 0xff; |
84 | if (ext) d[4]=0; | 84 | if (ext) |
85 | num=BN_bn2bin(a,&(d[4+ext])); | 85 | d[4] = 0; |
86 | num = BN_bn2bin(a, &(d[4 + ext])); | ||
86 | if (a->neg) | 87 | if (a->neg) |
87 | d[4]|=0x80; | 88 | d[4] |= 0x80; |
88 | return(num+4+ext); | 89 | return (num + 4 + ext); |
89 | } | 90 | } |
90 | 91 | ||
91 | BIGNUM *BN_mpi2bn(const unsigned char *d, int n, BIGNUM *a) | 92 | BIGNUM * |
92 | { | 93 | BN_mpi2bn(const unsigned char *d, int n, BIGNUM *a) |
94 | { | ||
93 | long len; | 95 | long len; |
94 | int neg=0; | 96 | int neg = 0; |
95 | 97 | ||
96 | if (n < 4) | 98 | if (n < 4) { |
97 | { | 99 | BNerr(BN_F_BN_MPI2BN, BN_R_INVALID_LENGTH); |
98 | BNerr(BN_F_BN_MPI2BN,BN_R_INVALID_LENGTH); | 100 | return (NULL); |
99 | return(NULL); | 101 | } |
100 | } | 102 | len = ((long)d[0] << 24) | ((long)d[1] << 16) | ((int)d[2] << 8) | |
101 | len=((long)d[0]<<24)|((long)d[1]<<16)|((int)d[2]<<8)|(int)d[3]; | 103 | (int)d[3]; |
102 | if ((len+4) != n) | 104 | if ((len + 4) != n) { |
103 | { | 105 | BNerr(BN_F_BN_MPI2BN, BN_R_ENCODING_ERROR); |
104 | BNerr(BN_F_BN_MPI2BN,BN_R_ENCODING_ERROR); | 106 | return (NULL); |
105 | return(NULL); | 107 | } |
106 | } | ||
107 | 108 | ||
108 | if (a == NULL) a=BN_new(); | 109 | if (a == NULL) |
109 | if (a == NULL) return(NULL); | 110 | a = BN_new(); |
111 | if (a == NULL) | ||
112 | return (NULL); | ||
110 | 113 | ||
111 | if (len == 0) | 114 | if (len == 0) { |
112 | { | 115 | a->neg = 0; |
113 | a->neg=0; | 116 | a->top = 0; |
114 | a->top=0; | 117 | return (a); |
115 | return(a); | 118 | } |
116 | } | 119 | d += 4; |
117 | d+=4; | ||
118 | if ((*d) & 0x80) | 120 | if ((*d) & 0x80) |
119 | neg=1; | 121 | neg = 1; |
120 | if (BN_bin2bn(d,(int)len,a) == NULL) | 122 | if (BN_bin2bn(d, (int)len, a) == NULL) |
121 | return(NULL); | 123 | return (NULL); |
122 | a->neg=neg; | 124 | a->neg = neg; |
123 | if (neg) | 125 | if (neg) { |
124 | { | 126 | BN_clear_bit(a, BN_num_bits(a) - 1); |
125 | BN_clear_bit(a,BN_num_bits(a)-1); | ||
126 | } | ||
127 | bn_check_top(a); | ||
128 | return(a); | ||
129 | } | 127 | } |
130 | 128 | bn_check_top(a); | |
129 | return (a); | ||
130 | } | ||