Esempio n. 1
1
		void rsa_key::verify_PKCS1_PSS(const void* digest, size_t digest_len, const void* buf, size_t /*buf_len*/, hash::message_digest_algorithm algorithm, int salt_len) const
		{
			assert(digest_len >= algorithm.result_size());

			if (digest_len < algorithm.result_size())
			{
				throw std::invalid_argument("digest_len");
			}

			//TODO: Use buf_len

			throw_error_if_not(RSA_verify_PKCS1_PSS(ptr().get(), static_cast<const unsigned char*>(digest), algorithm.raw(), static_cast<const unsigned char*>(buf), salt_len) != 0);
		}
Esempio n. 2
0
		void rsa_key::verify(const void* _sign, size_t sign_len, const void* buf, size_t buf_len, int type) const
		{
#if OPENSSL_VERSION_NUMBER >= 0x01000000
			throw_error_if_not(RSA_verify(type, static_cast<const unsigned char*>(buf), static_cast<unsigned int>(buf_len), static_cast<const unsigned char*>(_sign), static_cast<unsigned int>(sign_len), ptr().get()) != 0);
#else
			throw_error_if_not(RSA_verify(type, static_cast<unsigned char*>(const_cast<void*>(buf)), static_cast<unsigned int>(buf_len), static_cast<unsigned char*>(const_cast<void*>(_sign)), static_cast<unsigned int>(sign_len), ptr().get()) != 0);
#endif
		}
Esempio n. 3
0
		inline store store::create()
		{
			pointer _ptr = X509_STORE_new();

			throw_error_if_not(_ptr);

			return take_ownership(_ptr);
		}
		void hmac_context::initialize(const void* key, size_t key_len, const message_digest_algorithm* _algorithm, ENGINE* impl)
		{
#if OPENSSL_VERSION_NUMBER < 0x01000000
			HMAC_Init_ex(m_ctx, key, static_cast<int>(key_len), _algorithm ? _algorithm->raw() : NULL, impl);
#else
			throw_error_if_not(HMAC_Init_ex(m_ctx, key, static_cast<int>(key_len), _algorithm ? _algorithm->raw() : NULL, impl) != 0);
#endif
		}
Esempio n. 5
0
		size_t rsa_key::sign(void* out, size_t out_len, const void* buf, size_t buf_len, int type) const
		{
			unsigned int _out_len = static_cast<unsigned int>(out_len);

			throw_error_if_not(RSA_sign(type, static_cast<const unsigned char*>(buf), static_cast<unsigned int>(buf_len), static_cast<unsigned char*>(out), &_out_len, ptr().get()) != 0);

			return _out_len;
		}
		inline void hmac_context::update(const void* data, size_t len)
		{
#if OPENSSL_VERSION_NUMBER < 0x01000000
			HMAC_Update(m_ctx, static_cast<const unsigned char*>(data), static_cast<int>(len));
#else
			throw_error_if_not(HMAC_Update(m_ctx, static_cast<const unsigned char*>(data), static_cast<int>(len)) != 0);
#endif
		}
		size_t hmac_context::finalize(void* md, size_t len)
		{
			assert(md);

			unsigned int ilen = static_cast<unsigned int>(len);

#if OPENSSL_VERSION_NUMBER < 0x01000000
			HMAC_Final(m_ctx, static_cast<unsigned char*>(md), &ilen);
#else
			throw_error_if_not(HMAC_Final(m_ctx, static_cast<unsigned char*>(md), &ilen) != 0);
#endif
			return ilen;
		}
Esempio n. 8
0
		size_t rsa_key::private_decrypt(void* out, size_t out_len, const void* buf, size_t buf_len, int padding) const
		{
			assert(out_len >= size() - 41);

			if (out_len < size() - 41)
			{
				throw std::invalid_argument("out_len");
			}

			int result = RSA_private_decrypt(static_cast<int>(buf_len), static_cast<const unsigned char*>(buf), static_cast<unsigned char*>(out), ptr().get(), padding);

			throw_error_if_not(result >= 0);

			return result;
		}
Esempio n. 9
0
		size_t dh_key::compute_key(void* out, size_t out_len, bn::bignum pub_key) const
		{
			assert(out_len >= size());

			if (out_len < size())
			{
				throw std::invalid_argument("out_len");
			}

			int result = DH_compute_key(static_cast<unsigned char*>(out), pub_key.raw(), ptr().get());

			throw_error_if_not(result >= 0);

			return result;
		}
Esempio n. 10
0
		void rsa_key::padding_add_PKCS1_PSS(void* out, size_t out_len, const void* buf, size_t buf_len, hash::message_digest_algorithm algorithm, int salt_len) const
		{
			assert(out_len >= algorithm.result_size());
			assert(buf_len >= algorithm.result_size());

			if (out_len < algorithm.result_size())
			{
				throw std::invalid_argument("out_len");
			}

			if (buf_len < algorithm.result_size())
			{
				throw std::invalid_argument("buf_len");
			}

			throw_error_if_not(RSA_padding_add_PKCS1_PSS(ptr().get(), static_cast<unsigned char*>(out), static_cast<const unsigned char*>(buf), algorithm.raw(), salt_len) != 0);
		}
Esempio n. 11
0
		inline void utctime::print(bio::bio_ptr bio) const
		{
			throw_error_if_not(ASN1_UTCTIME_print(bio.raw(), ptr().get()) != 0);
		}
Esempio n. 12
0
		dh_key dh_key::take_ownership(pointer _ptr)
		{
			throw_error_if_not(_ptr);

			return dh_key(_ptr, deleter);
		}
Esempio n. 13
0
		inline void dh_key::print_parameters(file _file) const
		{
			throw_error_if_not(DHparams_print_fp(_file.raw(), ptr().get()) != 0);
		}
Esempio n. 14
0
		x509v3_context x509v3_context::take_ownership(pointer _ptr)
		{
			throw_error_if_not(_ptr);

			return x509v3_context(_ptr, deleter);
		}
Esempio n. 15
0
		inline const dh_key& dh_key::generate_key() const
		{
			throw_error_if_not(DH_generate_key(ptr().get()) != 0);

			return *this;
		}
Esempio n. 16
0
		inline void dh_key::print_parameters(bio::bio_ptr bio) const
		{
			throw_error_if_not(DHparams_print(bio.raw(), ptr().get()) != 0);
		}
Esempio n. 17
0
		string string::take_ownership(pointer _ptr)
		{
			throw_error_if_not(_ptr);

			return string(_ptr, deleter);
		}
Esempio n. 18
0
		inline void dh_key::check(int& codes) const
		{
			throw_error_if_not(DH_check(ptr().get(), &codes) != 0);
		}
Esempio n. 19
0
		inline void store::add_certificate(certificate cert)
		{
			throw_error_if_not(X509_STORE_add_cert(raw(), cert.raw()) != 0);
		}
Esempio n. 20
0
		inline X509_LOOKUP* store::add_lookup_method(X509_LOOKUP_METHOD* lookup_method)
		{
			X509_LOOKUP* lookup = X509_STORE_add_lookup(raw(), lookup_method);
			throw_error_if_not(lookup != NULL);
			return lookup;
		}
Esempio n. 21
0
		inline void utctime::set_time(const std::string& str) const
		{
			throw_error_if_not(ASN1_UTCTIME_set_string(ptr().get(), str.c_str()) != 0);
		}
Esempio n. 22
0
		inline void utctime::set_time(time_t time) const
		{
			throw_error_if_not(ASN1_UTCTIME_set(ptr().get(), time));
		}
Esempio n. 23
0
extension extension::take_ownership(pointer _ptr)
{
    throw_error_if_not(_ptr);

    return extension(_ptr, deleter);
}
Esempio n. 24
0
		inline void store::load_locations(const char* file, const char* dir)
		{
			throw_error_if_not(X509_STORE_load_locations(raw(), const_cast<char*>(file), const_cast<char*>(dir)) != 0);
		}
Esempio n. 25
0
		inline void dh_key::write_parameters(bio::bio_ptr bio) const
		{
			throw_error_if_not(PEM_write_bio_DHparams(bio.raw(), ptr().get()) != 0);
		}
Esempio n. 26
0
		inline void store::add_certificate_revocation_list(certificate_revocation_list crl)
		{
			throw_error_if_not(X509_STORE_add_crl(raw(), crl.raw()) != 0);
		}
Esempio n. 27
0
		inline void dh_key::write_parameters(file _file) const
		{
			throw_error_if_not(PEM_write_DHparams(_file.raw(), ptr().get()) != 0);
		}