19 Commits

Author SHA1 Message Date
kang1024 145d0c702b Add ML-KEM and ML-DSA support from OpenSSL 3.5.6
Port ML-KEM (FIPS 203) and ML-DSA (FIPS 204) post-quantum cryptography
from OpenSSL 3.5.6 to OpenSSL 3.0.9 with API compatibility adaptations.

Key compatibility shims:
- Add include/openssl/byteorder.h (OPENSSL_load/store_u{16,32,64}_le)
- Add include/internal/fips.h (ossl_fips_self_testing() inline stub)
- Map EVP_DigestSqueeze() to EVP_DigestFinalXOF() + large buffer
- Map EVP_MD_xof() to EVP_MD flags check
- Map OSSL_FUNC_SIGNATURE_SIGN/VERIFY_MESSAGE_INIT dispatch IDs to
  existing SIGN_INIT/VERIFY_INIT (2/4)
- Map EVP_PKEY_sign/verify_message_init() to sign/verify_init_ex()
- Add OSSL_SIGNATURE_PARAM_MU constant
- Add OSSL_FUNC typedef + OSSL_DISPATCH_END macro
- Use correct NID names (NID_id_alg_ml_dsa_44 vs NID_ML_DSA_44)

Provider registrations:
- ML-KEM KEM, ML-KEM/ML-DSA keymgmt, ML-DSA signature providers
- ML-KEM/ML-DSA encoders/decoders (der/pem/text for pub/priv/pkcs8)
- ML-KEM TLS group capabilities

Build system fixes:
- Add providers/common/provider_ctx.c with get_param/bool_param stubs
- Fix DER build.info $COMMON variable override order
- Fix decode_der2key.c PROV_CTX vs OSSL_LIB_CTX type mismatch (6 calls)
- Link ML tests against libcrypto.a (not .so) for internal symbols
- Remove references to missing der_ml_kem_{gen,key}.c

Adapt BUILD.gn for OpenHarmony:
- Add 18 new source files across three build sections (libcommon, libdefault,
  crypto_source) to support ML-KEM/ML-DSA in the OpenHarmony/OHOS build system.

Test infrastructure:
- Add 3 test recipes (evp_extra_ml_kem, internal_ml_kem, ml_dsa)
- Add #include "internal/nelem.h" for OSSL_NELEM in test files
- Add LABELED_BUF_PRINT_WIDTH definition for codec text output

All 253 tests pass (3374 test cases), 0 compilation warnings.

Signed-off-by: kang1024 <yangjiankang3@huawei.com>
2026-04-23 11:54:05 +08:00
Tomas Mraz e1dd0b3200 Fix timing side-channel in ECDSA signature computation
There is a timing signal of around 300 nanoseconds when the top word of
the inverted ECDSA nonce value is zero. This can happen with significant
probability only for some of the supported elliptic curves. In particular
the NIST P-521 curve is affected. To be able to measure this leak, the
attacker process must either be located in the same physical computer or
must have a very fast network connection with low latency.

Attacks on ECDSA nonce are also known as Minerva attack.

Fixes CVE-2024-13176

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/26429)

(cherry picked from commit 63c40a66c5dc287485705d06122d3a6e74a6a203)
Signed-off-by: lcc <lichaochen@huawei.com>
2025-01-22 17:57:55 +08:00
Tomas Mraz aa0bf2d5aa Rename BN_generate_dsa_nonce() to ossl_bn_gen_dsa_nonce_fixed_top()
And create a new BN_generate_dsa_nonce() that corrects the BIGNUM top.
We do this to avoid leaking fixed top numbers via the public API.

Also add a slight optimization in ossl_bn_gen_dsa_nonce_fixed_top()
and make it LE/BE agnostic.

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>

(cherry picked from commit 9c85f6cd2d6debe5ef6ef475ff4bf17e0985f7a2)

(Merged from https://github.com/openssl/openssl/pull/24317)

(cherry picked from commit fdc3efc371be43d5092bb19823e084f54541cbe3)
Signed-off-by: lcc <lichaochen@huawei.com>
2025-01-22 17:57:55 +08:00
Tomas Mraz 2f4e589fed Add ossl_bn_priv_rand_range_fixed_top() and use it for EC/DSA
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>

(cherry picked from commit 13b3ca5c998e6db4f7251a56c43541cb1a422bd0)

(Merged from https://github.com/openssl/openssl/pull/24317)

(cherry picked from commit a70ca93cdbc0ed36bf783b9eadc4cea35986b139)
Signed-off-by: lcc <lichaochen@huawei.com>
2025-01-22 17:57:55 +08:00
Tomas Mraz 960a5e5a57 Add ossl_bn_is_word_fixed_top()
Also correct some BN_FLG_FIXED_TOP flag handling.

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>

(cherry picked from commit 2d285fa873028f6cff9484a0cdf690fe05d7fb16)

(Merged from https://github.com/openssl/openssl/pull/24317)

(cherry picked from commit 5dbb2a8ca2c1ba42dfb9445b5ea76adccbdb9744)
Signed-off-by: lcc <lichaochen@huawei.com>
2025-01-22 17:57:55 +08:00
Richard Levitte 6f331fad8b Make DH_check_pub_key() and DH_generate_key() safer yet
We already check for an excessively large P in DH_generate_key(), but not in
DH_check_pub_key(), and none of them check for an excessively large Q.

This change adds all the missing excessive size checks of P and Q.

It's to be noted that behaviours surrounding excessively sized P and Q
differ.  DH_check() raises an error on the excessively sized P, but only
sets a flag for the excessively sized Q.  This behaviour is mimicked in
DH_check_pub_key().

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22518)

(cherry picked from commit ddeb4b6c6d527e54ce9a99cba785c0f7776e54b6)
Signed-off-by: code4lala <fengziteng2@huawei.com>
2023-11-16 16:27:35 +08:00
code4lala 78da00405e openssl-3.0.9.tar.gz
Signed-off-by: code4lala <fengziteng2@huawei.com>
2023-11-16 16:27:34 +08:00
code4lala f7de6b0b2f rm openssl 3.0.7
Signed-off-by: code4lala <fengziteng2@huawei.com>
2023-11-16 16:27:24 +08:00
Dmitry Belyavskiy b38bd22436 Fix Timing Oracle in RSA decryption
A timing based side channel exists in the OpenSSL RSA Decryption
implementation which could be sufficient to recover a plaintext across
a network in a Bleichenbacher style attack. To achieve a successful
decryption an attacker would have to be able to send a very large number
of trial messages for decryption. The vulnerability affects all RSA
padding modes: PKCS#1 v1.5, RSA-OEAP and RSASVE.

Patch written by Dmitry Belyavsky and Hubert Kario

CVE-2022-4304

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Signed-off-by: code4lala <fengziteng2@huawei.com>
Change-Id: Ib81f15484fa3374bf5f50baece50bb36d105d6d7
2023-04-26 14:20:29 +08:00
code4lala 393e3604f5 tar -xf openssl-openssl-3.0.7.tar.gz
Signed-off-by: code4lala <fengziteng2@huawei.com>
2023-04-12 11:12:14 +08:00
code4lala 05d2ef44d1 rm all
Signed-off-by: code4lala <fengziteng2@huawei.com>
2023-04-12 11:12:06 +08:00
Matt Caswell 628eb60bf5 Fix Timing Oracle in RSA decryption
A timing based side channel exists in the OpenSSL RSA Decryption
implementation which could be sufficient to recover a plaintext across
a network in a Bleichenbacher style attack. To achieve a successful
decryption an attacker would have to be able to send a very large number
of trial messages for decryption. The vulnerability affects all RSA
padding modes: PKCS#1 v1.5, RSA-OEAP and RSASVE.

Patch written by Dmitry Belyavsky and Hubert Kario

CVE-2022-4304

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Signed-off-by: code4lala <fengziteng2@huawei.com>
2023-02-10 10:33:33 +08:00
zhao_zhen_zhou 9fc77853dd 版本1.1.1k升级到1.1.ln并兼容MUSL
Signed-off-by: zhao_zhen_zhou <zhaozhenzhou@huawei.com>
2022-07-01 04:57:51 -07:00
wanghaixiang 78825ddaea [PATCH]CVE-2021-3711 and CVE-2021-3712
Signed-off-by: wanghaixiang <wanghaixiang@huawei.com>
2021-09-02 21:09:58 +08:00
HJ 0b759159b9 huangjun42@huawei.com
Signed-off-by: HJ <huangjun42@huawei.com>
2021-08-10 16:32:34 +08:00
mamingshuai 4f45966ee9 update openharmony 1.0.1 2021-03-11 20:38:52 +08:00
h00416433 ab6439910d Merge branch 'upstream/OpenSSL_1_1_1f' into hj20200529
Conflicts:
	CHANGES
	CONTRIBUTING
	Configurations/50-win-onecore.conf
	Configurations/90-team.norelease.conf
	Configurations/unix-Makefile.tmpl
	Configure
	NEWS
	NOTES.ANDROID
	README
	apps/rehash.c
	apps/s_cb.c
	apps/s_server.c
	apps/speed.c
	config
	crypto/aes/asm/aes-s390x.pl
	crypto/aes/asm/aesni-x86_64.pl
	crypto/aes/asm/aesp8-ppc.pl
	crypto/aes/asm/aesv8-armx.pl
	crypto/aes/asm/vpaes-armv8.pl
	crypto/aes/asm/vpaes-x86_64.pl
	crypto/asn1/charmap.h
	crypto/asn1/x_bignum.c
	crypto/bio/b_addr.c
	crypto/bio/bss_file.c
	crypto/bn/asm/armv8-mont.pl
	crypto/bn/asm/mips.pl
	crypto/bn/asm/ppc.pl
	crypto/bn/asm/rsaz-avx2.pl
	crypto/bn/asm/rsaz-x86_64.pl
	crypto/bn/asm/x86_64-mont5.pl
	crypto/bn/bn_local.h
	crypto/bn/bn_prime.c
	crypto/bn/bn_prime.h
	crypto/chacha/asm/chacha-armv8.pl
	crypto/cms/cms_att.c
	crypto/conf/conf_def.h
	crypto/conf/conf_lib.c
	crypto/dh/dh_gen.c
	crypto/dso/dso_dlfcn.c
	crypto/ec/asm/ecp_nistz256-armv8.pl
	crypto/ec/asm/ecp_nistz256-sparcv9.pl
	crypto/ec/asm/ecp_nistz256-x86_64.pl
	crypto/ec/asm/x25519-ppc64.pl
	crypto/ec/ec_asn1.c
	crypto/ec/ec_local.h
	crypto/ec/ecp_nistp224.c
	crypto/ec/ecp_nistp256.c
	crypto/ec/ecp_nistp521.c
	crypto/ec/ecp_nistz256.c
	crypto/ec/ecx_meth.c
	crypto/engine/eng_openssl.c
	crypto/err/err.c
	crypto/err/openssl.txt
	crypto/evp/e_aes.c
	crypto/evp/evp_err.c
	crypto/hmac/hmac.c
	crypto/modes/asm/ghash-x86_64.pl
	crypto/objects/obj_dat.h
	crypto/objects/obj_xref.h
	crypto/perlasm/x86_64-xlate.pl
	crypto/poly1305/asm/poly1305-armv8.pl
	crypto/ppccpuid.pl
	crypto/rand/drbg_lib.c
	crypto/rand/rand_err.c
	crypto/rand/rand_lib.c
	crypto/rand/rand_local.h
	crypto/rand/rand_unix.c
	crypto/rand/rand_vms.c
	crypto/rsa/rsa_ossl.c
	crypto/rsa/rsa_pk1.c
	crypto/rsa/rsa_pmeth.c
	crypto/rsa/rsa_ssl.c
	crypto/sha/asm/keccak1600-armv4.pl
	crypto/sha/asm/keccak1600-armv8.pl
	crypto/sha/asm/sha512-armv8.pl
	crypto/sha/asm/sha512-sparcv9.pl
	crypto/threads_none.c
	crypto/threads_win.c
	crypto/x509/x509_cmp.c
	crypto/x509/x509_vfy.c
	crypto/x509/x_crl.c
	crypto/x509v3/v3_purp.c
	doc/HOWTO/proxy_certificates.txt
	doc/man1/enc.pod
	doc/man1/s_client.pod
	doc/man1/x509.pod
	doc/man3/BN_generate_prime.pod
	doc/man3/CRYPTO_memcmp.pod
	doc/man3/EC_GROUP_copy.pod
	doc/man3/EVP_DigestSignInit.pod
	doc/man3/EVP_DigestVerifyInit.pod
	doc/man3/EVP_PKEY_new.pod
	doc/man3/EVP_SignInit.pod
	doc/man3/OPENSSL_malloc.pod
	doc/man3/RAND_bytes.pod
	doc/man3/RAND_set_rand_method.pod
	doc/man3/RSA_get0_key.pod
	doc/man3/SSL_SESSION_get0_hostname.pod
	doc/man3/SSL_get_error.pod
	doc/man3/X509_LOOKUP_meth_new.pod
	doc/man3/X509_STORE_add_cert.pod
	doc/man3/X509_cmp.pod
	doc/man3/X509_get_extension_flags.pod
	doc/man3/d2i_X509.pod
	doc/man5/config.pod
	doc/man7/Ed25519.pod
	doc/man7/X25519.pod
	e_os.h
	engines/e_afalg.c
	include/crypto/dso_conf.h.in
	include/internal/constant_time.h
	include/openssl/bio.h
	include/openssl/evperr.h
	include/openssl/lhash.h
	include/openssl/obj_mac.h
	include/openssl/opensslv.h
	include/openssl/randerr.h
	include/openssl/sslerr.h
	krb5
	ssl/record/rec_layer_s3.c
	ssl/s3_lib.c
	ssl/ssl_lib.c
	ssl/ssl_local.h
	ssl/statem/extensions.c
	ssl/statem/extensions_srvr.c
	ssl/statem/statem_lib.c
	ssl/statem/statem_srvr.c
	ssl/t1_lib.c
	ssl/tls13_enc.c
	test/bio_memleak_test.c
	test/bntest.c
	test/build.info
	test/certs/root-cert-rsa2.pem
	test/certs/server-pss-restrict-cert.pem
	test/certs/server-pss-restrict-key.pem
	test/certs/setup.sh
	test/dtlstest.c
	test/ec_internal_test.c
	test/ecdsatest.h
	test/ectest.c
	test/evp_extra_test.c
	test/recipes/02-test_errstr.t
	test/recipes/03-test_internal_ec.t
	test/recipes/30-test_evp_data/evpccmcavs.txt
	test/recipes/80-test_cms_data/bad_signtime_attr.cms
	test/recipes/80-test_cms_data/ct_multiple_attr.cms
	test/recipes/80-test_cms_data/no_ct_attr.cms
	test/recipes/80-test_cms_data/no_md_attr.cms
	test/recipes/90-test_bio_memleak.t
	test/recipes/90-test_includes_data/includes-eq-ws.cnf
	test/recipes/90-test_includes_data/includes-eq.cnf
	test/shlibloadtest.c
	test/ssl-tests/29-dtls-sctp-label-bug.conf
	test/ssl-tests/29-dtls-sctp-label-bug.conf.in
	test/sslapitest.c
	test/testutil.h
	test/testutil/random.c
	util/cavs-to-evptest.pl
	util/libcrypto.num
	util/perl/OpenSSL/Test.pm
	util/perl/TLSProxy/CertificateRequest.pm

Change-Id: I388e77b9fc937720aaf18841949f5f954ef2131b
2020-06-16 09:25:29 +08:00
Dr. Matthias St. Pierre fbbfd128c9 Fix header file include guard names
Make the include guards consistent by renaming them systematically according
to the naming conventions below

The public header files (in the 'include/openssl' directory) are not changed
in 1.1.1, because it is a stable release.

For the private header files files, the guard names try to match the path
specified in the include directives, with all letters converted to upper case
and '/' and '.' replaced by '_'. An extra 'OSSL_' is added as prefix.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9681)
2019-09-27 23:58:12 +02:00
Dr. Matthias St. Pierre 0c994d54af Reorganize private crypto header files
Currently, there are two different directories which contain internal
header files of libcrypto which are meant to be shared internally:

While header files in 'include/internal' are intended to be shared
between libcrypto and libssl, the files in 'crypto/include/internal'
are intended to be shared inside libcrypto only.

To make things complicated, the include search path is set up in such
a way that the directive #include "internal/file.h" could refer to
a file in either of these two directoroes. This makes it necessary
in some cases to add a '_int.h' suffix to some files to resolve this
ambiguity:

  #include "internal/file.h"      # located in 'include/internal'
  #include "internal/file_int.h"  # located in 'crypto/include/internal'

This commit moves the private crypto headers from

  'crypto/include/internal'  to  'include/crypto'

As a result, the include directives become unambiguous

  #include "internal/file.h"       # located in 'include/internal'
  #include "crypto/file.h"         # located in 'include/crypto'

hence the superfluous '_int.h' suffixes can be stripped.

The files 'store_int.h' and 'store.h' need to be treated specially;
they are joined into a single file.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9681)
2019-09-27 23:57:58 +02:00