summaryrefslogtreecommitdiff
path: root/src/LibsslDHKeyExchange.h
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-02-20 17:00:44 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-02-20 17:00:44 +0000
commitcfd0a40fdb8d1b1dccb53c3cbbaf34af037dbb55 (patch)
tree3de653027bffbac0323344695a4c2ec9ed68f784 /src/LibsslDHKeyExchange.h
parentdd8f18956a14e8ded60218666f3a21826b9591a1 (diff)
2008-02-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Proper return value handling for OpenSSL functions. * src/LibsslDHKeyExchange.h
Diffstat (limited to 'src/LibsslDHKeyExchange.h')
-rw-r--r--src/LibsslDHKeyExchange.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/LibsslDHKeyExchange.h b/src/LibsslDHKeyExchange.h
index 1f311d15..1f18849d 100644
--- a/src/LibsslDHKeyExchange.h
+++ b/src/LibsslDHKeyExchange.h
@@ -101,7 +101,7 @@ public:
handleError();
}
_privateKey = BN_new();
- if(!BN_rand(_privateKey, privateKeyBits, -1, false)) {
+ if(BN_rand(_privateKey, privateKeyBits, -1, false) == 0) {
handleError();
}
}
@@ -120,12 +120,13 @@ public:
size_t getPublicKey(unsigned char* out, size_t outLength) const
{
- if(outLength < publicKeyLength()) {
+ size_t pubKeyLen = publicKeyLength();
+ if(outLength < pubKeyLen) {
throw new DlAbortEx("Insufficient buffer for public key. expect:%u, actual:%u",
publicKeyLength(), outLength);
}
size_t nwritten = BN_bn2bin(_publicKey, out);
- if(!nwritten) {
+ if(nwritten != pubKeyLen) {
handleError();
}
return nwritten;
@@ -133,7 +134,7 @@ public:
void generateNonce(unsigned char* out, size_t outLength) const
{
- if(!RAND_bytes(out, outLength)) {
+ if(RAND_bytes(out, outLength) != 1) {
handleError();
}
}
@@ -142,7 +143,8 @@ public:
const unsigned char* peerPublicKeyData,
size_t peerPublicKeyLength) const
{
- if(outLength < publicKeyLength()) {
+ size_t pubKeyLen = publicKeyLength();
+ if(outLength < pubKeyLen) {
throw new DlAbortEx("Insufficient buffer for secret. expect:%u, actual:%u",
publicKeyLength(), outLength);
}
@@ -159,7 +161,7 @@ public:
size_t nwritten = BN_bn2bin(secret, out);
BN_free(secret);
- if(!nwritten) {
+ if(nwritten != pubKeyLen) {
handleError();
}
return nwritten;