safer
authorVolker Birk <vb@pep-project.org>
Wed, 22 Jun 2016 13:01:31 +0200
changeset 1197b1eac29288f
parent 118 397dc2da7805
child 120 5adccc3e3d3c
safer
GateKeeper.cpp
     1.1 --- a/GateKeeper.cpp	Wed Jun 22 12:47:18 2016 +0200
     1.2 +++ b/GateKeeper.cpp	Wed Jun 22 13:01:31 2016 +0200
     1.3 @@ -160,6 +160,7 @@
     1.4              r[i] = dist(gen);
     1.5  
     1.6          BCRYPT_OAEP_PADDING_INFO pi;
     1.7 +        memset(&pi, 0, sizeof(BCRYPT_OAEP_PADDING_INFO));
     1.8          pi.pszAlgId = BCRYPT_SHA256_ALGORITHM;
     1.9          pi.pbLabel = (PUCHAR) r;
    1.10          pi.cbLabel = sizeof(r);
    1.11 @@ -167,14 +168,19 @@
    1.12          ULONG result_size;
    1.13          PUCHAR _result = NULL;
    1.14          status = BCryptEncrypt(hUpdateKey, (PUCHAR) _update_key.data(), _update_key.size(), &pi, NULL, 0, NULL, 0, &result_size, BCRYPT_PAD_OAEP);
    1.15 -        if (status)
    1.16 +        if (status) {
    1.17 +            BCryptDestroyKey(hUpdateKey);
    1.18              throw runtime_error("BCryptEncrypt: calculating result size");
    1.19 +        }
    1.20  
    1.21          _result = new UCHAR[result_size];
    1.22          ULONG copied;
    1.23          status = BCryptEncrypt(hUpdateKey, (PUCHAR) _update_key.data(), _update_key.size(), &pi, NULL, 0, _result, result_size, &copied, BCRYPT_PAD_OAEP);
    1.24 -        if (status)
    1.25 +        if (status) {
    1.26 +            BCryptDestroyKey(hUpdateKey);
    1.27 +            delete[] _result;
    1.28              throw runtime_error("BCryptEncrypt: encrypting using update_key");
    1.29 +        }
    1.30  
    1.31          stringstream s;
    1.32          s << hex << setw(2) << setfill('0');