mirror of https://github.com/aria2/aria2
2008-02-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Proper return value handling for OpenSSL functions. * src/LibsslDHKeyExchange.hpull/1/head
parent
dd8f18956a
commit
cfd0a40fdb
|
@ -1,3 +1,8 @@
|
||||||
|
2008-02-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Proper return value handling for OpenSSL functions.
|
||||||
|
* src/LibsslDHKeyExchange.h
|
||||||
|
|
||||||
2008-02-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-02-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Random bytes generation using libgcrypt and OpenSSL.
|
Random bytes generation using libgcrypt and OpenSSL.
|
||||||
|
|
|
@ -101,7 +101,7 @@ public:
|
||||||
handleError();
|
handleError();
|
||||||
}
|
}
|
||||||
_privateKey = BN_new();
|
_privateKey = BN_new();
|
||||||
if(!BN_rand(_privateKey, privateKeyBits, -1, false)) {
|
if(BN_rand(_privateKey, privateKeyBits, -1, false) == 0) {
|
||||||
handleError();
|
handleError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,12 +120,13 @@ public:
|
||||||
|
|
||||||
size_t getPublicKey(unsigned char* out, size_t outLength) const
|
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",
|
throw new DlAbortEx("Insufficient buffer for public key. expect:%u, actual:%u",
|
||||||
publicKeyLength(), outLength);
|
publicKeyLength(), outLength);
|
||||||
}
|
}
|
||||||
size_t nwritten = BN_bn2bin(_publicKey, out);
|
size_t nwritten = BN_bn2bin(_publicKey, out);
|
||||||
if(!nwritten) {
|
if(nwritten != pubKeyLen) {
|
||||||
handleError();
|
handleError();
|
||||||
}
|
}
|
||||||
return nwritten;
|
return nwritten;
|
||||||
|
@ -133,7 +134,7 @@ public:
|
||||||
|
|
||||||
void generateNonce(unsigned char* out, size_t outLength) const
|
void generateNonce(unsigned char* out, size_t outLength) const
|
||||||
{
|
{
|
||||||
if(!RAND_bytes(out, outLength)) {
|
if(RAND_bytes(out, outLength) != 1) {
|
||||||
handleError();
|
handleError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +143,8 @@ public:
|
||||||
const unsigned char* peerPublicKeyData,
|
const unsigned char* peerPublicKeyData,
|
||||||
size_t peerPublicKeyLength) const
|
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",
|
throw new DlAbortEx("Insufficient buffer for secret. expect:%u, actual:%u",
|
||||||
publicKeyLength(), outLength);
|
publicKeyLength(), outLength);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +161,7 @@ public:
|
||||||
|
|
||||||
size_t nwritten = BN_bn2bin(secret, out);
|
size_t nwritten = BN_bn2bin(secret, out);
|
||||||
BN_free(secret);
|
BN_free(secret);
|
||||||
if(!nwritten) {
|
if(nwritten != pubKeyLen) {
|
||||||
handleError();
|
handleError();
|
||||||
}
|
}
|
||||||
return nwritten;
|
return nwritten;
|
||||||
|
|
Loading…
Reference in New Issue