rsa.c (162856) | rsa.c (164149) |
---|---|
1/* $OpenBSD: rsa.c,v 1.28 2006/08/03 03:34:42 deraadt Exp $ */ | 1/* $OpenBSD: rsa.c,v 1.29 2006/11/06 21:25:28 markus Exp $ */ |
2/* 3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 5 * All rights reserved 6 * 7 * As far as I am concerned, the code I have written for this software 8 * can be used freely for any purpose. Any derived versions of this 9 * software must be clearly marked as such, and if the derived work is --- 76 unchanged lines hidden (view full) --- 86 ilen = BN_num_bytes(in); 87 inbuf = xmalloc(ilen); 88 BN_bn2bin(in, inbuf); 89 90 if ((len = RSA_public_encrypt(ilen, inbuf, outbuf, key, 91 RSA_PKCS1_PADDING)) <= 0) 92 fatal("rsa_public_encrypt() failed"); 93 | 2/* 3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 5 * All rights reserved 6 * 7 * As far as I am concerned, the code I have written for this software 8 * can be used freely for any purpose. Any derived versions of this 9 * software must be clearly marked as such, and if the derived work is --- 76 unchanged lines hidden (view full) --- 86 ilen = BN_num_bytes(in); 87 inbuf = xmalloc(ilen); 88 BN_bn2bin(in, inbuf); 89 90 if ((len = RSA_public_encrypt(ilen, inbuf, outbuf, key, 91 RSA_PKCS1_PADDING)) <= 0) 92 fatal("rsa_public_encrypt() failed"); 93 |
94 BN_bin2bn(outbuf, len, out); | 94 if (BN_bin2bn(outbuf, len, out) == NULL) 95 fatal("rsa_public_encrypt: BN_bin2bn failed"); |
95 96 memset(outbuf, 0, olen); 97 memset(inbuf, 0, ilen); 98 xfree(outbuf); 99 xfree(inbuf); 100} 101 102int --- 8 unchanged lines hidden (view full) --- 111 ilen = BN_num_bytes(in); 112 inbuf = xmalloc(ilen); 113 BN_bn2bin(in, inbuf); 114 115 if ((len = RSA_private_decrypt(ilen, inbuf, outbuf, key, 116 RSA_PKCS1_PADDING)) <= 0) { 117 error("rsa_private_decrypt() failed"); 118 } else { | 96 97 memset(outbuf, 0, olen); 98 memset(inbuf, 0, ilen); 99 xfree(outbuf); 100 xfree(inbuf); 101} 102 103int --- 8 unchanged lines hidden (view full) --- 112 ilen = BN_num_bytes(in); 113 inbuf = xmalloc(ilen); 114 BN_bn2bin(in, inbuf); 115 116 if ((len = RSA_private_decrypt(ilen, inbuf, outbuf, key, 117 RSA_PKCS1_PADDING)) <= 0) { 118 error("rsa_private_decrypt() failed"); 119 } else { |
119 BN_bin2bn(outbuf, len, out); | 120 if (BN_bin2bn(outbuf, len, out) == NULL) 121 fatal("rsa_private_decrypt: BN_bin2bn failed"); |
120 } 121 memset(outbuf, 0, olen); 122 memset(inbuf, 0, ilen); 123 xfree(outbuf); 124 xfree(inbuf); 125 return len; 126} 127 --- 4 unchanged lines hidden (view full) --- 132 BIGNUM *aux; 133 BN_CTX *ctx; 134 135 if ((aux = BN_new()) == NULL) 136 fatal("rsa_generate_additional_parameters: BN_new failed"); 137 if ((ctx = BN_CTX_new()) == NULL) 138 fatal("rsa_generate_additional_parameters: BN_CTX_new failed"); 139 | 122 } 123 memset(outbuf, 0, olen); 124 memset(inbuf, 0, ilen); 125 xfree(outbuf); 126 xfree(inbuf); 127 return len; 128} 129 --- 4 unchanged lines hidden (view full) --- 134 BIGNUM *aux; 135 BN_CTX *ctx; 136 137 if ((aux = BN_new()) == NULL) 138 fatal("rsa_generate_additional_parameters: BN_new failed"); 139 if ((ctx = BN_CTX_new()) == NULL) 140 fatal("rsa_generate_additional_parameters: BN_CTX_new failed"); 141 |
140 BN_sub(aux, rsa->q, BN_value_one()); 141 BN_mod(rsa->dmq1, rsa->d, aux, ctx); | 142 if ((BN_sub(aux, rsa->q, BN_value_one()) == 0) || 143 (BN_mod(rsa->dmq1, rsa->d, aux, ctx) == 0) || 144 (BN_sub(aux, rsa->p, BN_value_one()) == 0) || 145 (BN_mod(rsa->dmp1, rsa->d, aux, ctx) == 0)) 146 fatal("rsa_generate_additional_parameters: BN_sub/mod failed"); |
142 | 147 |
143 BN_sub(aux, rsa->p, BN_value_one()); 144 BN_mod(rsa->dmp1, rsa->d, aux, ctx); 145 | |
146 BN_clear_free(aux); 147 BN_CTX_free(ctx); 148} 149 | 148 BN_clear_free(aux); 149 BN_CTX_free(ctx); 150} 151 |