summaryrefslogtreecommitdiff
path: root/rsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'rsa.c')
-rw-r--r--rsa.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/rsa.c b/rsa.c
index 66561a421..bec1d190b 100644
--- a/rsa.c
+++ b/rsa.c
@@ -1,3 +1,4 @@
1/* $OpenBSD: rsa.c,v 1.29 2006/11/06 21:25:28 markus Exp $ */
1/* 2/*
2 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -60,11 +61,15 @@
60 */ 61 */
61 62
62#include "includes.h" 63#include "includes.h"
63RCSID("$OpenBSD: rsa.c,v 1.24 2001/12/27 18:22:16 markus Exp $");
64 64
65#include <sys/types.h>
66
67#include <stdarg.h>
68#include <string.h>
69
70#include "xmalloc.h"
65#include "rsa.h" 71#include "rsa.h"
66#include "log.h" 72#include "log.h"
67#include "xmalloc.h"
68 73
69void 74void
70rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key) 75rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key)
@@ -86,7 +91,8 @@ rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key)
86 RSA_PKCS1_PADDING)) <= 0) 91 RSA_PKCS1_PADDING)) <= 0)
87 fatal("rsa_public_encrypt() failed"); 92 fatal("rsa_public_encrypt() failed");
88 93
89 BN_bin2bn(outbuf, len, out); 94 if (BN_bin2bn(outbuf, len, out) == NULL)
95 fatal("rsa_public_encrypt: BN_bin2bn failed");
90 96
91 memset(outbuf, 0, olen); 97 memset(outbuf, 0, olen);
92 memset(inbuf, 0, ilen); 98 memset(inbuf, 0, ilen);
@@ -111,7 +117,8 @@ rsa_private_decrypt(BIGNUM *out, BIGNUM *in, RSA *key)
111 RSA_PKCS1_PADDING)) <= 0) { 117 RSA_PKCS1_PADDING)) <= 0) {
112 error("rsa_private_decrypt() failed"); 118 error("rsa_private_decrypt() failed");
113 } else { 119 } else {
114 BN_bin2bn(outbuf, len, out); 120 if (BN_bin2bn(outbuf, len, out) == NULL)
121 fatal("rsa_private_decrypt: BN_bin2bn failed");
115 } 122 }
116 memset(outbuf, 0, olen); 123 memset(outbuf, 0, olen);
117 memset(inbuf, 0, ilen); 124 memset(inbuf, 0, ilen);
@@ -132,11 +139,11 @@ rsa_generate_additional_parameters(RSA *rsa)
132 if ((ctx = BN_CTX_new()) == NULL) 139 if ((ctx = BN_CTX_new()) == NULL)
133 fatal("rsa_generate_additional_parameters: BN_CTX_new failed"); 140 fatal("rsa_generate_additional_parameters: BN_CTX_new failed");
134 141
135 BN_sub(aux, rsa->q, BN_value_one()); 142 if ((BN_sub(aux, rsa->q, BN_value_one()) == 0) ||
136 BN_mod(rsa->dmq1, rsa->d, aux, ctx); 143 (BN_mod(rsa->dmq1, rsa->d, aux, ctx) == 0) ||
137 144 (BN_sub(aux, rsa->p, BN_value_one()) == 0) ||
138 BN_sub(aux, rsa->p, BN_value_one()); 145 (BN_mod(rsa->dmp1, rsa->d, aux, ctx) == 0))
139 BN_mod(rsa->dmp1, rsa->d, aux, ctx); 146 fatal("rsa_generate_additional_parameters: BN_sub/mod failed");
140 147
141 BN_clear_free(aux); 148 BN_clear_free(aux);
142 BN_CTX_free(ctx); 149 BN_CTX_free(ctx);