Skip to content

Commit

Permalink
hotplace rev.372 cbor_object_signing_encryption::composer::parse, con…
Browse files Browse the repository at this point in the history
…st EVP_PKEY*
  • Loading branch information
princeb612 committed Oct 27, 2023
1 parent 063ef32 commit 2e97b4f
Show file tree
Hide file tree
Showing 39 changed files with 692 additions and 536 deletions.
2 changes: 1 addition & 1 deletion sdk/base/system/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <sdk/base/types.hpp>

#if defined _WIN32 || defined _WIN64
#include <windows.h>
#include <sdk/base/system/windows/types.hpp>
#elif defined __linux__
#include <pthread.h>
#endif
Expand Down
7 changes: 4 additions & 3 deletions sdk/base/system/windows/sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
* Date Name Description
*/

#include <comdef.h>
#include <comutil.h>

#include <sdk/base/system/windows/sdk.hpp>
#include <sdk/base/system/windows/windows_version.hpp>

// COM
#include <comdef.h>
#include <comutil.h>

namespace hotplace {

return_t com_runtime_startup(uint32 init) {
Expand Down
2 changes: 0 additions & 2 deletions sdk/base/system/windows/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
* Date Name Description
*/

#include <windows.h>

#include <sdk/base/system/windows/semaphore.hpp>

namespace hotplace {
Expand Down
1 change: 1 addition & 0 deletions sdk/base/system/windows/semaphore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <sdk/base/error.hpp>
#include <sdk/base/system/semaphore.hpp>
#include <sdk/base/system/windows/types.hpp>

namespace hotplace {

Expand Down
2 changes: 2 additions & 0 deletions sdk/base/system/windows/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#define __HOTPLACE_SDK_BASE_SYSTEM_WINDOWS_TYPES__

// #warning Please include winsock2.h before windows.h
#include <mswsock.h>
#include <winsock2.h>
#include <ws2tcpip.h>
// winsock2.h before windows.h
#include <windows.h>

Expand Down
1 change: 1 addition & 0 deletions sdk/crypto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <sdk/crypto/basic/crypto_advisor.hpp>
#include <sdk/crypto/basic/crypto_key.hpp>
#include <sdk/crypto/basic/crypto_keychain.hpp>
#include <sdk/crypto/basic/evp_key.hpp>
#include <sdk/crypto/basic/hmac_otp.hpp>
#include <sdk/crypto/basic/openssl_chacha20.hpp>
#include <sdk/crypto/basic/openssl_crypt.hpp>
Expand Down
13 changes: 7 additions & 6 deletions sdk/crypto/basic/crypto_advisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <sdk/base/system/trace.hpp>
#include <sdk/crypto/basic/crypto_advisor.hpp>
#include <sdk/crypto/basic/evp_key.hpp>
#include <sdk/io/system/sdk.hpp>

namespace hotplace {
Expand Down Expand Up @@ -694,7 +695,7 @@ return_t crypto_advisor::ktyof_ec_curve(const char* curve, uint32& kty) {
return ret;
}

return_t crypto_advisor::ktyof_ec_curve(EVP_PKEY* pkey, std::string& kty) {
return_t crypto_advisor::ktyof_ec_curve(const EVP_PKEY* pkey, std::string& kty) {
return_t ret = errorcode_t::success;

__try2 {
Expand Down Expand Up @@ -727,7 +728,7 @@ return_t crypto_advisor::ktyof_ec_curve(EVP_PKEY* pkey, std::string& kty) {
return ret;
}

return_t crypto_advisor::nameof_ec_curve(EVP_PKEY* pkey, std::string& name) {
return_t crypto_advisor::nameof_ec_curve(const EVP_PKEY* pkey, std::string& name) {
return_t ret = errorcode_t::success;
uint32 nid = 0;

Expand All @@ -746,7 +747,7 @@ return_t crypto_advisor::nameof_ec_curve(EVP_PKEY* pkey, std::string& name) {
return ret;
}

bool crypto_advisor::is_kindof(EVP_PKEY* pkey, const char* alg) {
bool crypto_advisor::is_kindof(const EVP_PKEY* pkey, const char* alg) {
bool test = false;

__try2 {
Expand All @@ -771,7 +772,7 @@ bool crypto_advisor::is_kindof(EVP_PKEY* pkey, const char* alg) {
return test;
}

bool crypto_advisor::is_kindof(EVP_PKEY* pkey, jwa_t alg) {
bool crypto_advisor::is_kindof(const EVP_PKEY* pkey, jwa_t alg) {
bool test = false;

__try2 {
Expand All @@ -790,7 +791,7 @@ bool crypto_advisor::is_kindof(EVP_PKEY* pkey, jwa_t alg) {
return test;
}

bool crypto_advisor::is_kindof(EVP_PKEY* pkey, crypt_sig_t sig) {
bool crypto_advisor::is_kindof(const EVP_PKEY* pkey, crypt_sig_t sig) {
bool test = false;

__try2 {
Expand Down Expand Up @@ -827,7 +828,7 @@ bool crypto_advisor::is_kindof(EVP_PKEY* pkey, crypt_sig_t sig) {
return test;
}

bool crypto_advisor::is_kindof(EVP_PKEY* pkey, jws_t sig) {
bool crypto_advisor::is_kindof(const EVP_PKEY* pkey, jws_t sig) {
bool test = false;

__try2 {
Expand Down
72 changes: 14 additions & 58 deletions sdk/crypto/basic/crypto_advisor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,25 +362,25 @@ class crypto_advisor {
return_t ktyof_ec_curve(const char* curve, uint32& kty);
/**
* @brief kty
* @param EVP_PKEY* pkey [in]
* @param const EVP_PKEY* pkey [in]
* @param std::string& kty [out]
* oct
* RSA
* EC
* OKP
* @return error code (see error.hpp)
*/
return_t ktyof_ec_curve(EVP_PKEY* pkey, std::string& kty);
return_t ktyof_ec_curve(const EVP_PKEY* pkey, std::string& kty);
/**
* @brief kty
* @param EVP_PKEY* pkey [in]
* @param const EVP_PKEY* pkey [in]
* @param crypto_kty_t& kty [out] crypto_kty_t::kty_hmac, crypto_kty_t::kty_rsa, crypto_kty_t::kty_ec, crypto_kty_t::kty_okp
* @return error code (see error.hpp)
*/
return_t ktyof_ec_curve(EVP_PKEY* pkey, crypto_kty_t& kty);
return_t ktyof_ec_curve(const EVP_PKEY* pkey, crypto_kty_t& kty);
/**
* @brief "alg" from key
* @param EVP_PKEY* pkey [in]
* @param const EVP_PKEY* pkey [in]
* @param std::string& curve_name [out]
* "P-256", "P384", "P-521", "Ed25519", "Ed448", "X25519", "X448"
* @return error code (see error.hpp)
Expand All @@ -389,36 +389,36 @@ class crypto_advisor {
* advisor->nameof_ec_curve (pkey, curve_name);
* }
*/
return_t nameof_ec_curve(EVP_PKEY* pkey, std::string& curve_name);
return_t nameof_ec_curve(const EVP_PKEY* pkey, std::string& curve_name);

/**
* @brief kind of
* @param EVP_PKEY* pkey [in]
* @param const EVP_PKEY* pkey [in]
* @param jwa_t alg [in]
* @return true if match, false if not
*/
bool is_kindof(EVP_PKEY* pkey, jwa_t alg);
bool is_kindof(const EVP_PKEY* pkey, jwa_t alg);
/**
* @brief kind of
* @param EVP_PKEY* pkey [in]
* @param const EVP_PKEY* pkey [in]
* @param crypt_sig_t sig [in]
* @return true if match, false if not
*/
bool is_kindof(EVP_PKEY* pkey, crypt_sig_t sig);
bool is_kindof(const EVP_PKEY* pkey, crypt_sig_t sig);
/**
* @brief kind of
* @param EVP_PKEY* pkey [in]
* @param const EVP_PKEY* pkey [in]
* @param jws_t sig [in]
* @return true if match, false if not
*/
bool is_kindof(EVP_PKEY* pkey, jws_t sig);
bool is_kindof(const EVP_PKEY* pkey, jws_t sig);
/**
* @brief kind of
* @param EVP_PKEY* pkey [in]
* @param const EVP_PKEY* pkey [in]
* @param const char* alg [in] signature algorithms
* @return true if match, false if not
*/
bool is_kindof(EVP_PKEY* pkey, const char* alg);
bool is_kindof(const EVP_PKEY* pkey, const char* alg);

cose_kty_t ktyof(crypto_kty_t kty);
crypto_kty_t ktyof(cose_kty_t kty);
Expand Down Expand Up @@ -501,50 +501,6 @@ class crypto_advisor {
md_byname_map_t _md_byname_map;
};

/**
* @brief curve
* @param EVP_PKEY* key [in]
* @param uint32& nid [out]
* 415 : NID_X9_62_prime256v1 (prime256v1)
* 715 : NID_secp384r1 (secp384r1)
* 716 : NID_secp521r1 (secp521r1)
* 1087: NID_ED25519
* 1088: NID_ED448
* @remarks
* opensource native type
*
* # define EVP_PKEY_HMAC NID_hmac
* # define EVP_PKEY_RSA NID_rsaEncryption
* # define EVP_PKEY_EC NID_X9_62_id_ecPublicKey
* # define EVP_PKEY_X25519 NID_X25519
* # define EVP_PKEY_X448 NID_X448
* # define EVP_PKEY_ED25519 NID_ED25519
* # define EVP_PKEY_ED448 NID_ED448
*
* #define NID_hmac 855
* #define NID_rsaEncryption 6
* #define NID_X9_62_id_ecPublicKey 408
* #define NID_X25519 1034
* #define NID_X448 1035
* #define NID_ED25519 1087
* #define NID_ED448 1088
*
* #define NID_X9_62_prime256v1 415
* #define NID_secp384r1 715
* #define NID_secp521r1 716
*/
return_t nidof_evp_pkey(EVP_PKEY* key, uint32& nid);
/**
* @brief kindof
* @param EVP_PKEY* pkey [in]
*/
bool kindof_ecc(EVP_PKEY* pkey);

/**
* @param EVP_PKEY* key [in]
*/
crypto_kty_t typeof_crypto_key(EVP_PKEY* key);

extern const hint_cipher_t evp_cipher_methods[];
extern const hint_digest_t evp_md_methods[];
extern const hint_blockcipher_t hint_blockciphers[];
Expand Down
Loading

0 comments on commit 2e97b4f

Please sign in to comment.