summaryrefslogtreecommitdiffstats
path: root/SoftHSMv2/src/lib/crypto/OSSLGOSTPrivateKey.cpp
diff options
context:
space:
mode:
authorNingSun <ning.sun@intel.com>2018-03-14 16:35:31 -0700
committerNingSun <ning.sun@intel.com>2018-03-14 17:02:47 -0700
commitda00ff6db5e68773996ec79d711c45fb3444c580 (patch)
tree0387aa1f70a468e6c3264767454ae6f4528f59e8 /SoftHSMv2/src/lib/crypto/OSSLGOSTPrivateKey.cpp
parent535535b7c5f2781fa096a5fd00a762d24db4eddc (diff)
Remove win32 support in SoftHSMv2
Due to license issue, we have to remove win32 support in SoftHSMv2. Issue-ID: AAF-151 Change-Id: I31dda45ed84065819e26be8205747dd096a37432 Signed-off-by: NingSun <ning.sun@intel.com>
Diffstat (limited to 'SoftHSMv2/src/lib/crypto/OSSLGOSTPrivateKey.cpp')
-rw-r--r--SoftHSMv2/src/lib/crypto/OSSLGOSTPrivateKey.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/SoftHSMv2/src/lib/crypto/OSSLGOSTPrivateKey.cpp b/SoftHSMv2/src/lib/crypto/OSSLGOSTPrivateKey.cpp
index 6371e8f..a68b720 100644
--- a/SoftHSMv2/src/lib/crypto/OSSLGOSTPrivateKey.cpp
+++ b/SoftHSMv2/src/lib/crypto/OSSLGOSTPrivateKey.cpp
@@ -36,6 +36,7 @@
#include "OSSLGOSTPrivateKey.h"
#include "OSSLUtil.h"
#include <string.h>
+#include <openssl/x509.h>
#include <openssl/ec.h>
// DER of a private key
@@ -172,13 +173,36 @@ bool OSSLGOSTPrivateKey::deserialise(ByteString& serialised)
ByteString OSSLGOSTPrivateKey::PKCS8Encode()
{
ByteString der;
- // TODO
+ if (pkey == NULL) return der;
+ PKCS8_PRIV_KEY_INFO* p8inf = EVP_PKEY2PKCS8(pkey);
+ if (p8inf == NULL) return der;
+ int len = i2d_PKCS8_PRIV_KEY_INFO(p8inf, NULL);
+ if (len < 0)
+ {
+ PKCS8_PRIV_KEY_INFO_free(p8inf);
+ return der;
+ }
+ der.resize(len);
+ unsigned char* priv = &der[0];
+ int len2 = i2d_PKCS8_PRIV_KEY_INFO(p8inf, &priv);
+ PKCS8_PRIV_KEY_INFO_free(p8inf);
+ if (len2 != len) der.wipe();
return der;
}
// Decode from PKCS#8 BER
-bool OSSLGOSTPrivateKey::PKCS8Decode(const ByteString& /*ber*/)
+bool OSSLGOSTPrivateKey::PKCS8Decode(const ByteString& ber)
{
- return false;
+ int len = ber.size();
+ if (len <= 0) return false;
+ const unsigned char* priv = ber.const_byte_str();
+ PKCS8_PRIV_KEY_INFO* p8 = d2i_PKCS8_PRIV_KEY_INFO(NULL, &priv, len);
+ if (p8 == NULL) return false;
+ EVP_PKEY* key = EVP_PKCS82PKEY(p8);
+ PKCS8_PRIV_KEY_INFO_free(p8);
+ if (key == NULL) return false;
+ setFromOSSL(key);
+ EVP_PKEY_free(key);
+ return true;
}
#endif