Example #1
0
extern "C" int32_t
CryptoNative_RsaSign(int32_t type, const uint8_t* m, int32_t mlen, uint8_t* sigret, int32_t* siglen, RSA* rsa)
{
    if (siglen == nullptr)
    {
        assert(false);
        return 0;
    }

    *siglen = 0;

    if (HasNoPrivateKey(rsa))
    {
        ERR_PUT_error(ERR_LIB_RSA, RSA_F_RSA_SIGN, RSA_R_VALUE_MISSING, __FILE__, __LINE__);
        return 0;
    }

    // Shared pointer to the metadata about the message digest algorithm
    const EVP_MD* digest = EVP_get_digestbynid(type);

    // If the digest itself isn't known then RSA_R_UNKNOWN_ALGORITHM_TYPE will get reported, but
    // we have to check that the digest size matches what we expect.
    if (digest != nullptr && mlen != EVP_MD_size(digest))
    {
        ERR_PUT_error(ERR_LIB_RSA, RSA_F_RSA_SIGN, RSA_R_INVALID_MESSAGE_LENGTH, __FILE__, __LINE__);
        return 0;
    }

    unsigned int unsignedSigLen = 0;
    int32_t ret = RSA_sign(type, m, UnsignedCast(mlen), sigret, &unsignedSigLen, rsa);
    assert(unsignedSigLen <= INT32_MAX);
    *siglen = static_cast<int32_t>(unsignedSigLen);
    return ret;
}
Example #2
0
static void
ERR_NSS_error(int function, int reason, const char *file, int line) {
    if (NSS_lib_error_code == 0)
        NSS_lib_error_code = ERR_get_next_error_library();

    ERR_PUT_error(NSS_lib_error_code, function, reason, file, line);
}
Example #3
0
void
ERR_pk11_error(int function, int reason, char *file, int line)
{
	if (pk11_lib_error_code == 0)
		pk11_lib_error_code = ERR_get_next_error_library();
	ERR_PUT_error(pk11_lib_error_code, function, reason, file, line);
}
static void
ERR_devcrypto_error(int function, int reason, char *file, int line)
{
	if (devcrypto_error_code == 0)
		devcrypto_error_code = ERR_get_next_error_library();
	ERR_PUT_error(devcrypto_error_code, function, reason, file, line);
}
Example #5
0
/*
 * The SUNWerr macro resolves to this routine. So when we need
 * to push an error, this routine does it for us. Notice that
 * the SUNWerr macro provides a filename and line #.
 */
void
ERR_SUNW_error(int function, int reason, char *file, int line)
{
	assert(SUNW_lib_error_code != 0);
#ifndef OPENSSL_NO_ERR
	ERR_PUT_error(SUNW_lib_error_code, function, reason, file, line);
#endif
}
Example #6
0
extern "C" int32_t CryptoNative_RsaSignPrimitive(int32_t flen, const uint8_t* from, uint8_t* to, RSA* rsa)
{
    if (HasNoPrivateKey(rsa))
    {
        ERR_PUT_error(ERR_LIB_RSA, RSA_F_RSA_PRIVATE_ENCRYPT, RSA_R_VALUE_MISSING, __FILE__, __LINE__);
        return -1;
    }

    return RSA_private_encrypt(flen, from, to, rsa, RSA_NO_PADDING);
}
Example #7
0
extern "C" int32_t
CryptoNative_RsaPrivateDecrypt(int32_t flen, const uint8_t* from, uint8_t* to, RSA* rsa, RsaPadding padding)
{
    if (HasNoPrivateKey(rsa))
    {
        ERR_PUT_error(ERR_LIB_RSA, RSA_F_RSA_PRIVATE_DECRYPT, RSA_R_VALUE_MISSING, __FILE__, __LINE__);
        return -1;
    }

    int openSslPadding = GetOpenSslPadding(padding);
    return RSA_private_decrypt(flen, from, to, rsa, openSslPadding);
}
static void err_put_ms_error(DWORD ms_err, int func, const char *file, int line)
{
    static int init = 0;
#   define ERR_MAP_SZ 16
    static struct {
	int err;
	DWORD ms_err;	    /* I don't think we get more than 16 *different* errors */
    } err_map[ERR_MAP_SZ];  /* in here, before we give up the whole thing...        */
    int i;

    if (ms_err == 0)
	/* 0 is not an error */
	return;
    if (!init) {
	ERR_load_strings(ERR_LIB_CRYPTOAPI, CRYPTOAPI_str_functs);
	memset(&err_map, 0, sizeof(err_map));
	init++;
    }
    /* since MS error codes are 32 bit, and the ones in the ERR_... system is
     * only 12, we must have a mapping table between them.  */
    for (i = 0; i < ERR_MAP_SZ; i++) {
	if (err_map[i].ms_err == ms_err) {
	    ERR_PUT_error(ERR_LIB_CRYPTOAPI, func, err_map[i].err, file, line);
	    break;
	} else if (err_map[i].ms_err == 0 ) {
	    /* end of table, add new entry */
	    ERR_STRING_DATA *esd = calloc(2, sizeof(*esd));
	    if (esd == NULL)
		break;
	    err_map[i].ms_err = ms_err;
	    err_map[i].err = esd->error = i + 100;
	    esd->string = ms_error_text(ms_err);
	    check_malloc_return(esd->string);
	    ERR_load_strings(ERR_LIB_CRYPTOAPI, esd);
	    ERR_PUT_error(ERR_LIB_CRYPTOAPI, func, err_map[i].err, file, line);
	    break;
	}
    }
}
Example #9
0
int32_t CryptoNative_DsaSign(
    DSA* dsa,
    const uint8_t* hash,
    int32_t hashLength,
    uint8_t* refsignature,
    int32_t* outSignatureLength)
{
    if (outSignatureLength == NULL || dsa == NULL)
    {
        assert(false);
        return 0;
    }

    // DSA_OpenSSL() returns a shared pointer, no need to free/cache.
    if (DSA_get_method(dsa) == DSA_OpenSSL())
    {
        const BIGNUM* privKey;

        DSA_get0_key(dsa, NULL, &privKey);

        if (!privKey)
        {
            *outSignatureLength = 0;
            ERR_PUT_error(ERR_LIB_DSA, DSA_F_DSA_DO_SIGN, DSA_R_MISSING_PARAMETERS, __FILE__, __LINE__);
            return 0;
        }
    }

    unsigned int unsignedSigLen = 0;
    int32_t success = DSA_sign(0, hash, hashLength, refsignature, &unsignedSigLen, dsa);
    if (!success) // Only 0 and 1 returned
    {
        *outSignatureLength = 0;
        return 0;
    }

    assert(unsignedSigLen <= INT32_MAX);
    *outSignatureLength = (int32_t)unsignedSigLen;
    return 1;
}
Example #10
0
static void ERR_RSAREF_error(int function, int reason, char *file, int line)
{
    if (RSAREF_lib_error_code == 0)
        RSAREF_lib_error_code = ERR_get_next_error_library();
    ERR_PUT_error(RSAREF_lib_error_code, function, reason, file, line);
}
Example #11
0
void
SSL_error_internal(const SSL *s, int r, char *f, int l)
{
	ERR_PUT_error(ERR_LIB_SSL,
	    (SSL_state_func_code(S3I(s)->hs.state)), r, f, l);
}
void ERR_BECEEM_error(int function, int reason, char *file, int line)
	{
	if (BECEEM_lib_error_code == 0)
		BECEEM_lib_error_code = ERR_get_next_error_library();
	ERR_PUT_error(BECEEM_lib_error_code, function, reason, file, line);
	}
Example #13
0
static void ERR_HWCRHK_error(int function, int reason, char *file, int line)
{
    if (HWCRHK_lib_error_code == 0)
        HWCRHK_lib_error_code = ERR_get_next_error_library();
    ERR_PUT_error(HWCRHK_lib_error_code, function, reason, file, line);
}
static void ERR_SUREWARE_error(int function, int reason, char *file, int line)
	{
	if (SUREWARE_lib_error_code == 0)
		SUREWARE_lib_error_code=ERR_get_next_error_library();
	ERR_PUT_error(SUREWARE_lib_error_code,function,reason,file,line);
	}
Example #15
0
static void ERR_ATALLA_error(int function, int reason, char *file, int line)
{
    if (ATALLA_lib_error_code == 0)
        ATALLA_lib_error_code = ERR_get_next_error_library();
    ERR_PUT_error(ATALLA_lib_error_code, function, reason, file, line);
}
Example #16
0
static void ERR_DEADCAFE_error(int function, int reason, char *file, int line)
	{
	if (DEADCAFE_lib_error_code == 0)
		DEADCAFE_lib_error_code=ERR_get_next_error_library();
	ERR_PUT_error(DEADCAFE_lib_error_code,function,reason,file,line);
	}
Example #17
0
static void ERR_Cryptography_OSRandom_error(int function, int reason,
                                            char *file, int line)
{
    ERR_PUT_error(Cryptography_OSRandom_lib_error_code, function, reason,
                  file, line);
}
static void ERR_CCA4758_error(int function, int reason, char *file, int line)
	{
	if (CCA4758_lib_error_code == 0)
		CCA4758_lib_error_code=ERR_get_next_error_library();
	ERR_PUT_error(CCA4758_lib_error_code,function,reason,file,line);
	}
Example #19
0
static void ERR_CAPI_error(int function, int reason, char *file, int line)
{
    if (lib_code == 0)
        lib_code = ERR_get_next_error_library();
    ERR_PUT_error(lib_code, function, reason, file, line);
}