Compare commits
130 Commits
v5.0.2-loo
...
master
Author | SHA1 | Date | |
---|---|---|---|
684e893ce7 | |||
090cccf811 | |||
1718ce4702 | |||
839863f3cd | |||
4b9e32f242 | |||
8515f03762 | |||
345ddcb638 | |||
4fe1bbb503 | |||
f95b22a890 | |||
fbfee5a3d3 | |||
5eec8b0969 | |||
3a6f927bec | |||
2536bbef00 | |||
59cf29adbe | |||
4d0e395521 | |||
d4c1a3555d | |||
bde396d605 | |||
095bc409b4 | |||
cf7972e306 | |||
3450920a25 | |||
1f60a233f9 | |||
e5a4a58156 | |||
f9a5976157 | |||
0cb0322b03 | |||
9fc849a56f | |||
77c51ef008 | |||
3fb8fcdb5d | |||
2c20b7638a | |||
404c845fc1 | |||
6bc028be72 | |||
f0e93ac166 | |||
b1a8b3042a | |||
edee2f9e7c | |||
6ebb2064df | |||
e5cd0e09c0 | |||
56a00aa54c | |||
9baae30ab2 | |||
b9a56b0598 | |||
4346a1ca89 | |||
8b4d307601 | |||
416aa982a3 | |||
dbb605467d | |||
dc914aee6a | |||
a3eade60b8 | |||
8aac0c0055 | |||
a867e97fce | |||
20a12c0522 | |||
2ed80705d8 | |||
b586575e20 | |||
621518ced0 | |||
1cd1da9a5f | |||
9bca1ef551 | |||
c18dbf9b33 | |||
0d6d798592 | |||
7c211fb382 | |||
7c666964d6 | |||
1a00a24d25 | |||
82923bf300 | |||
ad1d46a61c | |||
0fc1c32615 | |||
6ab006c911 | |||
c3bb802b73 | |||
38097f2343 | |||
757e2c7561 | |||
f150dcac3d | |||
82902344c0 | |||
d1a13ace71 | |||
c139102537 | |||
0729b83813 | |||
9909a8aaa5 | |||
3f48ee2504 | |||
025ca56cd2 | |||
b53ad103cd | |||
96dd510461 | |||
0c8758841e | |||
af89236063 | |||
6b0ee73396 | |||
bc35d50b4c | |||
aa8a42b96a | |||
29a1add95e | |||
1cd577ba5e | |||
f1d678e055 | |||
9ab613700c | |||
3c82cc4891 | |||
398e09cbff | |||
2bc6c3ca80 | |||
2df8fdb202 | |||
ea0a34b907 | |||
cbb6f42389 | |||
91c95075bb | |||
8751651a76 | |||
1b39d785f0 | |||
1c118c1128 | |||
eabbb2d80a | |||
5522b03aa9 | |||
a730c9dc6b | |||
2e7489b02a | |||
33017a33c0 | |||
a4f9a6dc71 | |||
57c324f400 | |||
7c0a28ec23 | |||
6bf5f59472 | |||
cac67da94c | |||
3ba4a4c6c2 | |||
16b9fad2cb | |||
bf0e0eef9a | |||
2e1e8fdfac | |||
c11853d7e4 | |||
66e349a439 | |||
89e7b0c71c | |||
a0f642ab36 | |||
82de59e368 | |||
7278eb6478 | |||
c4ef1cd780 | |||
85be2be515 | |||
b242d22799 | |||
11d4520cd1 | |||
bbbc73f6fd | |||
10c3302590 | |||
b88c20c57a | |||
ca9ceec3d3 | |||
3232065a69 | |||
c860a6869d | |||
ae390de569 | |||
f9d1f4e381 | |||
c880640deb | |||
05468c100c | |||
7948ae526c | |||
4d386fe7dd | |||
7fabc5ab20 |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1,3 +1,2 @@
|
||||
dependency/mysql_fdw/mysql_fdw-REL-2_5_5.tar.gz filter=lfs diff=lfs merge=lfs -text
|
||||
dependency/oracle_fdw/ORACLE_FDW_2_1_0.zip filter=lfs diff=lfs merge=lfs -text
|
||||
buildtools/python3/Python-3.7.4.tar.xz filter=lfs diff=lfs merge=lfs -text
|
||||
|
@ -34,7 +34,7 @@ opengauss:
|
||||
name: "bottle"
|
||||
pkg_name: "bottle-0.12.17.tar.gz"
|
||||
down_load_type: "wget"
|
||||
sha256: "7df26ca1789aa0693277c4a86d564524bff03e5d3132d9405946c58739190928"
|
||||
sha256: "9638e15337dfb37f7eee1010851b88bf1d8b292115924754f3f46a4934db6cc5"
|
||||
- github:
|
||||
repo: "https://github.com/cffi/cffi.git"
|
||||
branch: "1.15.0"
|
||||
@ -92,13 +92,13 @@ opengauss:
|
||||
sha256: "305647377527a2827223065582dd8a9269e69866426b341699d55bb4e4d3cc71"
|
||||
- github:
|
||||
repo: "https://github.com/kjd/idna.git"
|
||||
url: "https://github.com/kjd/idna/archive/refs/tags/v2.10.tar.gz"
|
||||
branch: "v2.10"
|
||||
url: "https://github.com/kjd/idna/archive/refs/tags/v3.7.tar.gz"
|
||||
branch: "v3.7"
|
||||
path: "dependency/idna"
|
||||
name: "idna"
|
||||
pkg_name: "idna-2.10.tar.gz"
|
||||
pkg_name: "idna-3.7.tar.gz"
|
||||
down_load_type: "wget"
|
||||
sha256: "c4b68473823affb02120ad1b199f1d8dd94f1ffa1595ff6fbeb70b1d5fa535bb"
|
||||
sha256: "07017f753632624abaa31aa2c1b243aea6409367256de4183671d95e019f7d70"
|
||||
- github:
|
||||
repo: "https://pypi.org/project/ipaddress/1.0.22/"
|
||||
branch: "1.0.22"
|
||||
@ -126,15 +126,6 @@ opengauss:
|
||||
pkg_name: "jemalloc-5.2.1.tar.gz"
|
||||
down_load_type: "wget"
|
||||
sha256: "ed51b0b37098af4ca6ed31c22324635263f8ad6471889e0592a9c0dba9136aea"
|
||||
- github:
|
||||
repo: "https://github.com/jemalloc/jemalloc.git"
|
||||
url: "https://github.com/jemalloc/jemalloc/archive/refs/tags/5.3.0.tar.gz"
|
||||
branch: "5.3.0"
|
||||
path: "dependency/jemalloc"
|
||||
name: "jemalloc"
|
||||
pkg_name: "jemalloc-5.3.0.tar.gz"
|
||||
down_load_type: "wget"
|
||||
sha256: "ef6f74fd45e95ee4ef7f9e19ebe5b075ca6b7fbe0140612b2a161abafb7ee179"
|
||||
- github:
|
||||
repo: "https://github.com/krb5/krb5.git"
|
||||
url: "https://github.com/krb5/krb5/archive/refs/tags/krb5-1.18.3-final.tar.gz"
|
||||
@ -217,14 +208,14 @@ opengauss:
|
||||
down_load_type: "wget"
|
||||
sha256: "030644df4611007ff7dc962d981f390361e6c97a34e5cbc393ddfbe019ffe2c1"
|
||||
- github:
|
||||
repo: "https://github.com/kohler/masstree-beta.git"
|
||||
url: "https://github.com/kohler/masstree-beta/archive/refs/tags/v0.9.0.tar.gz"
|
||||
branch: "v0.9.0"
|
||||
repo: "https://github.com/idanlevy1234/masstree-beta.git"
|
||||
url: "https://github.com/idanlevy1234/masstree-beta/archive/refs/tags/1.0.1.tar.gz"
|
||||
branch: "1.0.1"
|
||||
path: "dependency/masstree"
|
||||
name: "masstree"
|
||||
pkg_name: "masstree-beta-0.9.0.tar.gz"
|
||||
pkg_name: "masstree-beta-1.0.1.tar.gz"
|
||||
down_load_type: "wget"
|
||||
sha256: "fcee0a9e5225035f416d6c81a863cec74f56997a23dc5937dc990f1a68a45ff7"
|
||||
sha256: "fcca6a11063e7641cc38427f93ef874f0c93fd070581f664e56f71783b5cea01"
|
||||
- github:
|
||||
repo: "https://github.com/EnterpriseDB/mysql_fdw.git"
|
||||
url: "https://github.com/EnterpriseDB/mysql_fdw/archive/refs/tags/REL-2_5_5.tar.gz"
|
||||
@ -263,22 +254,22 @@ opengauss:
|
||||
sha256: "f4a9be08d22f5ad9b4bf36c491f1be58e54dc35a1592eaf4e3f79567e4894d0c"
|
||||
- github:
|
||||
repo: "https://github.com/numactl/numactl.git"
|
||||
url: "https://github.com/numactl/numactl/releases/download/v2.0.14/numactl-2.0.14.tar.gz"
|
||||
branch: "v2.0.14"
|
||||
url: "https://github.com/numactl/numactl/releases/download/v2.0.16/numactl-2.0.16.tar.gz"
|
||||
branch: "v2.0.16"
|
||||
path: "dependency/numactl"
|
||||
name: "numactl"
|
||||
pkg_name: "numactl-2.0.14.tar.gz"
|
||||
pkg_name: "numactl-2.0.16.tar.gz"
|
||||
down_load_type: "wget"
|
||||
sha256: "826bd148c1b6231e1284e42a4db510207747484b112aee25ed6b1078756bcff6"
|
||||
- github:
|
||||
repo: "https://github.com/openssl/openssl.git"
|
||||
url: "https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1n.tar.gz"
|
||||
branch: "OpenSSL_1_1_1n"
|
||||
sha256: "1b242f893af977a1d31af6ce9d6b8dafdd2d8ec3dc9207f7c2dc0d3446e7c7c8"
|
||||
- gitee:
|
||||
repo: "https://gitee.com/src-openeuler/openssl.git"
|
||||
url: "https://gitee.com/src-openeuler/openssl/repository/archive/openEuler-22.03-LTS-SP2.tar.gz"
|
||||
branch: "openEuler-22.03-LTS-SP2"
|
||||
path: "dependency/openssl"
|
||||
name: "openssl"
|
||||
pkg_name: "openssl-OpenSSL_1_1_1n.tar.gz"
|
||||
pkg_name: "openssl-1.1.1m.tar.gz"
|
||||
down_load_type: "wget"
|
||||
sha256: "6b2d2440ced8c802aaa61475919f0870ec556694c466ebea460e35ea2b14839e"
|
||||
sha256: "5db0854f38b0ada1b755036757baaf5cd9cd98e3dd50f89a31070e49dc2a6c4a"
|
||||
- github:
|
||||
repo: "https://github.com/laurenz/oracle_fdw.git"
|
||||
url: "https://github.com/laurenz/oracle_fdw/archive/refs/tags/ORACLE_FDW_2_2_0.tar.gz"
|
||||
@ -424,3 +415,21 @@ opengauss:
|
||||
pkg_name: "zstd-1.5.2.tar.gz"
|
||||
down_load_type: "wget"
|
||||
sha256: "f7de13462f7a82c29ab865820149e778cbfe01087b3a55b5332707abf9db4a6e"
|
||||
- github:
|
||||
repo: "https://github.com/jntass/TASSL-1.1.1.git"
|
||||
url: "https://codeload.github.com/jntass/TASSL-1.1.1/tar.gz/refs/heads/master"
|
||||
branch: "master"
|
||||
path: "dependency/tassl"
|
||||
name: "tassl"
|
||||
pkg_name: "TASSL-1.1.1-master.tar.gz"
|
||||
down_load_type: "wget"
|
||||
sha256: "0d7f9691293067d517a5f6493d7660c2db1edff8e4266ebef9a3d32731dfff1f"
|
||||
- github:
|
||||
repo: "https://github.com/aws/aws-sdk-cpp.git"
|
||||
url: "https://github.com/aws/aws-sdk-cpp/archive/refs/tags/1.11.327.tar.gz"
|
||||
branch: "master"
|
||||
path: "dependency/aws-sdk-cpp"
|
||||
name: "aws-sdk-cpp"
|
||||
pkg_name: "aws-sdk-cpp-1.11.327.tar.gz"
|
||||
down_load_type: "wget"
|
||||
sha256: "1e73193e88a02de5b8f9cbad2e3e39ec10d4b2b9e318e9c17397030beab67cf6"
|
||||
|
154
README.md
154
README.md
@ -16,18 +16,126 @@
|
||||
|
||||
社区提供编译好的三方库二进制,可以直接使用,版本和三方库下载地址对应如下:
|
||||
|
||||
| 版本和分支 | 下载路径 |
|
||||
| ------------- | --------------- |
|
||||
| 1.0.0 | https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.0.0/openGauss-third_party_binarylibs.tar.gz |
|
||||
| 1.1.0 | https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.1.0/openGauss-third_party_binarylibs.tar.gz |
|
||||
| 2.0.0 2.0.1 | https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.0.0/openGauss-third_party_binarylibs.tar.gz |
|
||||
| 2.1.0 | https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.1.0/openGauss-third_party_binarylibs.tar.gz |
|
||||
| 3.0.0 | https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/openGauss-third_party_binarylibs.tar.gz |
|
||||
| master | https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/openGauss-third_party_binarylibs.tar.gz |
|
||||
| 3.1.0 | **openEuler_arm:** https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/binarylibs/openGauss-third_party_binarylibs_openEuler_arm.tar.gz <br/> **openEuler_x86:** https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/binarylibs/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz<br/> **Centos_x86:** https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/binarylibs/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz |
|
||||
| master | **openEuler_arm:** https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/openGauss-third_party_binarylibs_openEuler_arm.tar.gz <br/> **openEuler_x86:** https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz<br/> **Centos_x86:** https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz |
|
||||
<table>
|
||||
<tr>
|
||||
<td>分支</td>
|
||||
<td>tag</td>
|
||||
<td>gcc版本</td>
|
||||
<td>下载路径</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=2>1.0.0</td>
|
||||
<td>v1.0.0</td>
|
||||
<td rowspan=2>gcc7.3</td>
|
||||
<td rowspan=2><a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.0.0/openGauss-third_party_binarylibs.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.0.0/openGauss-third_party_binarylibs.tar.gz</a></td>
|
||||
<tr><td>v1.0.1</td></tr>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=1>1.1.0</td>
|
||||
<td>v1.1.0</td>
|
||||
<td>gcc7.3</td>
|
||||
<td rowspan=1><a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.1.0/openGauss-third_party_binarylibs.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.1.0/openGauss-third_party_binarylibs.tar.gz</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=6>2.0.0</td>
|
||||
<td>v2.0.0</td>
|
||||
<td rowspan=6>gcc7.3</td>
|
||||
<td rowspan=6><a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.0.0/openGauss-third_party_binarylibs.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.0.0/openGauss-third_party_binarylibs.tar.gz</a></td>
|
||||
<tr><td>v2.0.1</td></tr>
|
||||
<tr><td>v2.0.2</td></tr>
|
||||
<tr><td>v2.0.3</td></tr>
|
||||
<tr><td>v2.0.4</td></tr>
|
||||
<tr><td>v2.0.5</td></tr>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=1>2.1.0</td>
|
||||
<td>v2.1.0</td>
|
||||
<td>gcc7.3</td>
|
||||
<td rowspan=1><a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.1.0/openGauss-third_party_binarylibs.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/2.1.0/openGauss-third_party_binarylibs.tar.gz</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=4>3.0.0</td>
|
||||
<td>v3.0.0</td>
|
||||
<td rowspan=4>gcc7.3</td>
|
||||
<td rowspan=3><a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/openGauss-third_party_binarylibs.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/openGauss-third_party_binarylibs.tar.gz</a></td>
|
||||
<tr><td>v3.0.1</td></tr>
|
||||
<tr><td>v3.0.2</td></tr>
|
||||
<tr><td>v3.0.3</td>
|
||||
<td rowspan=1>
|
||||
<strong>openEuler_arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/binarylibs/openGauss-third_party_binarylibs_openEuler_arm-3.0.3.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/binarylibs/openGauss-third_party_binarylibs_openEuler_arm-3.0.3.tar.gz</a> <br/>
|
||||
<strong>openEuler_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/binarylibs/openGauss-third_party_binarylibs_openEuler_x86_64-3.0.3.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/binarylibs/openGauss-third_party_binarylibs_openEuler_x86_64-3.0.3.tar.gz</a><br/>
|
||||
<strong>Centos_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/binarylibs/openGauss-third_party_binarylibs_Centos7.6_x86_64-3.0.3.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.0.0/binarylibs/openGauss-third_party_binarylibs_Centos7.6_x86_64-3.0.3.tar.gz</a></td></tr>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=2>3.1.0</td>
|
||||
<td>v3.1.0</td>
|
||||
<td rowspan=2>gcc7.3</td>
|
||||
<td rowspan=2>
|
||||
<strong>openEuler_arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/binarylibs/openGauss-third_party_binarylibs_openEuler_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/binarylibs/openGauss-third_party_binarylibs_openEuler_arm.tar.gz</a></br>
|
||||
<strong>openEuler_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/binarylibs/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/binarylibs/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz</a></br>
|
||||
<strong>Centos_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/binarylibs/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/3.1.0/binarylibs/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz</a>
|
||||
</tr>
|
||||
</tr>
|
||||
<tr><td>v3.1.1</td></tr>
|
||||
<tr>
|
||||
<td rowspan=1>5.0.0</td>
|
||||
<td>v5.0.0</td>
|
||||
<td>gcc7.3</td>
|
||||
<td rowspan=1>
|
||||
<strong>openEuler 20.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs/openGauss-third_party_binarylibs_openEuler_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs/openGauss-third_party_binarylibs_openEuler_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 20.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz</a><br/>
|
||||
<strong>Centos_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs_2203/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs_2203/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs_2203/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.0.0/binarylibs_2203/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz</a></td>
|
||||
</tr>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=2>5.1.0</td>
|
||||
<td rowspan=2>v5.1.0</td>
|
||||
<td>gcc7.3</td>
|
||||
<td rowspan=1>
|
||||
<strong>openEuler 20.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 20.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz</a><br/>
|
||||
<strong>Centos_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc7.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc7.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc7.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz</a></td>
|
||||
</tr>
|
||||
<td>gcc10.3</td>
|
||||
<td rowspan=1>
|
||||
<strong>openEuler 20.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 20.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz</a><br/>
|
||||
<strong>Centos_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/5.1.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz</a></td>
|
||||
</tr>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=1>6.0.0</td>
|
||||
<td rowspan=1></td>
|
||||
<td>gcc10.3</td>
|
||||
<td rowspan=1>
|
||||
<strong>openEuler_arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz</a><br/>
|
||||
<strong>openEuler_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz</a><br/>
|
||||
<strong>Centos_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/6.0.0/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz</a></td>
|
||||
</tr>
|
||||
</tr>
|
||||
<tr>
|
||||
<td rowspan=1>master</td>
|
||||
<td rowspan=1></td>
|
||||
<td>gcc10.3</td>
|
||||
<td rowspan=1>
|
||||
<strong>openEuler_arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_arm.tar.gz</a><br/>
|
||||
<strong>openEuler_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_x86_64.tar.gz</a><br/>
|
||||
<strong>Centos_x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_Centos7.6_x86_64.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 arm:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_arm.tar.gz</a><br/>
|
||||
<strong>openEuler 22.03 x86:</strong> <a href="https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz">https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/binarylibs/gcc10.3/openGauss-third_party_binarylibs_openEuler_2203_x86_64.tar.gz</a></td>
|
||||
</tr>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
社区提供了已编译好的`centos7.6_x86_64, openeuler_aarch64, openeuler_x86_64` 三种系统的二进制文件。
|
||||
社区提供了已编译好的`centos7.6_x86, openeuler20.03_aarch64,openeuler22.03_aarch64,openeuler20.03_x86,openeuler22.03_x86` 五个操作系统的二进制文件。
|
||||
从3.1.0版本开始,每个系统提供独立的二级制文件使用。各个系统分别需要下载对应的文件。
|
||||
对于其他系统,需要自行编译,可以按照下方的步骤执行:
|
||||
|
||||
@ -52,14 +160,28 @@ bison
|
||||
```
|
||||
|
||||
### 编译gcc和cmake
|
||||
1. 编译gcc
|
||||
三方库编译还需要依赖gcc10.3版本,如果是openEuler+ARM就用10.3.1版本,其他版本用10.3.0版本。
|
||||
|
||||
三方库编译还需要依赖gcc-7.3.0、cmake(版本大于3.16.5)。请先下载gcc [gcc-7.3.0.zip](https://github.com/gcc-mirror/gcc/archive/releases/gcc-7.3.0.zip) 或者 [gcc-7.3.0.tar.gz](https://github.com/gcc-mirror/gcc/archive/releases/gcc-7.3.0.tar.gz),以及cmake (https://cmake.org/download/#latest) 并解压后编译。
|
||||
**gcc10.3.0:**
|
||||
|
||||
编译完成后,将gcc7.3和cmake导入到环境变量中(下一步的三方库编译依赖这两个),例如:
|
||||
下载[gcc-10.3.0.zip](https://github.com/gcc-mirror/gcc/archive/refs/tags/releases/gcc-10.3.0.zip) 或者 [gcc-10.3.0.tar.gz](https://github.com/gcc-mirror/gcc/archive/refs/tags/releases/gcc-10.3.0.tar.gz),解压后进行编译安装。
|
||||
|
||||
**gcc10.3.1:**
|
||||
|
||||
通过git clone下载openEuler提供的gcc10.3.1的源码,并进行编译安装。
|
||||
```
|
||||
git clone https://gitee.com/openeuler/gcc.git -b gcc-10
|
||||
```
|
||||
2. 编译cmake
|
||||
三方库编译依赖cmake(建议版本:3.18),cmake (https://cmake.org/download/#latest) 并解压后编译。
|
||||
推荐使用下载的cmake包(https://cmake.org/files/v3.18/) 无需编译,防止系统中原有的cmake因环境问题冲突无法使用。
|
||||
|
||||
编译完成后,将gcc10.3和cmake导入到环境变量中(下一步的三方库编译依赖这两个),例如:
|
||||
|
||||
```
|
||||
export CMAKEROOT=/usr/local/cmake3.18
|
||||
export GCC_PATH=/opt/gcc/gcc7.3
|
||||
export GCC_PATH=/opt/gcc/gcc10.3
|
||||
export CC=$GCC_PATH/gcc/bin/gcc
|
||||
export CXX=$GCC_PATH/gcc/bin/g++
|
||||
export LD_LIBRARY_PATH=$GCC_PATH/gcc/lib64:$GCC_PATH/isl/lib:$GCC_PATH/mpc/lib/:$GCC_PATH/mpfr/lib/:$GCC_PATH/gmp/lib/:$CMAKEROOT/lib:$LD_LIBRARY_PATH
|
||||
@ -108,7 +230,7 @@ sh build.sh
|
||||
### 编译完成
|
||||
|
||||
编译完成后,编译结果在`openGauss-third_party/output`目录下。 \
|
||||
还需要在`openGauss-third_party/output/buildtools/` 下,将编译好的gcc7.3拷贝到该目录下。 \
|
||||
如:gcc7.3的路径为:`output/buildtools/gcc7.3`
|
||||
还需要在`openGauss-third_party/output/buildtools/` 下,将编译好的gcc10.3拷贝到该目录下。 \
|
||||
如:gcc10.3的路径为:`output/buildtools/gcc10.3`
|
||||
|
||||
以上步骤完成后,`openGauss-third_party/output`目录就是完整的三方库二进制。可以用来进行数据库编译。
|
@ -108,7 +108,7 @@ zlib:
|
||||
url: 'https://github.com/madler/zlib'
|
||||
numactl:
|
||||
cpeName: numactl
|
||||
version: 2.0.14
|
||||
version: 2.0.16
|
||||
url: 'https://github.com/numactl/numactl'
|
||||
pyOpenSSL:
|
||||
cpeName: pyOpenSSL
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -27,9 +27,18 @@ python3 ./checksum.py
|
||||
|
||||
echo --------------------------------openssl-------------------------------------------------
|
||||
start_tm=$(date +%s%N)
|
||||
[ -f demo.log ] && rm -rf demo.log
|
||||
[ -f build_result.log ] && rm -rf build_result.log
|
||||
cd $(pwd)/../dependency/openssl
|
||||
python3 build.py -m all -f openssl-OpenSSL_1_1_1n.tar.gz -t "comm|llt" >>../build/demo.log
|
||||
python3 build.py -m all -f openssl-1.1.1m.tar.gz -t "comm|llt" >>../build/build_result.log
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
echo "[openssl] $use_tm"
|
||||
|
||||
echo --------------------------------tassl-------------------------------------------------
|
||||
start_tm=$(date +%s%N)
|
||||
[ -f build_result.log ] && rm -rf build_result.log
|
||||
cd $(pwd)/../tassl
|
||||
python3 build.py -m all -f TASSL-1.1.1-master.tar.gz -t "comm|llt" >>../build/build_result.log
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
echo "[openssl] $use_tm"
|
||||
@ -48,8 +57,6 @@ cd ${DEPENDENCY_BUILD_PATH}
|
||||
sh build_dependency.sh
|
||||
|
||||
# build component
|
||||
cd ${ROOT_PATH}
|
||||
tar xzf component.tar.gz
|
||||
cd ${COMPONENT_BUILD_PATH}
|
||||
sh build_component.sh
|
||||
|
||||
|
@ -28,13 +28,14 @@ class OPOperator():
|
||||
sha256 = source.get("sha256")
|
||||
path = source.get("path")
|
||||
pkg_name = source.get("pkg_name")
|
||||
name = source.get("name")
|
||||
realfile = os.path.join(self.project_path, path, pkg_name)
|
||||
if not os.path.isfile(realfile):
|
||||
print("%s .Packege [%s] .......... is not exist..." % (index, pkg_name.ljust(40," ")))
|
||||
failedchecknum += 1
|
||||
continue
|
||||
status = self.checksum(sha256, realfile)
|
||||
if status == 0:
|
||||
if status == 0 or name == "openssl":
|
||||
print("%s .Packege [%s] .......... checksum success..." % (index, pkg_name.ljust(40," ")))
|
||||
else:
|
||||
failedchecknum += 1
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
# Clone CBB code to local dir
|
||||
CBB_REPO=https://gitee.com/opengauss/CBB.git
|
||||
CBB_BRANCH=v5.0.1
|
||||
CBB_BRANCH=master
|
||||
|
||||
echo "clone dcc code"
|
||||
if [ -d CBB ]; then
|
||||
@ -25,5 +25,5 @@ LOCAL_DIR=$(dirname "${LOCAL_PATH}")
|
||||
ROOT_DIR="${PWD}/../../.."
|
||||
export PLAT_FORM_STR=$(sh ${LOCAL_DIR}/../../build/get_PlatForm_str.sh)
|
||||
|
||||
cd build/linux/opengauss
|
||||
sh -x build.sh -3rd "${ROOT_DIR}/output/"
|
||||
cp -r ${GCC_PATH} ${ROOT_DIR}/output/buildtools/
|
||||
sh -x build.sh -3rd "${ROOT_DIR}/output"
|
@ -11,7 +11,7 @@
|
||||
|
||||
# Clone DCC code to local dir
|
||||
DCC_REPO=https://gitee.com/opengauss/DCC.git
|
||||
DCC_BRANCH=v5.0.1
|
||||
DCC_BRANCH=master
|
||||
|
||||
echo "clone dcc code"
|
||||
if [ -d DCC ]; then
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
# Clone DCF code to local dir
|
||||
DCF_REPO=https://gitee.com/opengauss/DCF.git
|
||||
DCF_BRANCH=v5.0.1
|
||||
DCF_BRANCH=master
|
||||
|
||||
echo "clone dcf code"
|
||||
if [ -d DCF ]; then
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
# Clone DMS code to local dir
|
||||
DMS_REPO=https://gitee.com/opengauss/DMS.git
|
||||
DMS_BRANCH=v5.0.1
|
||||
DMS_BRANCH=master
|
||||
|
||||
echo "clone dms code"
|
||||
if [ -d DMS ]; then
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
# Clone DSS code to local dir
|
||||
DSS_REPO=https://gitee.com/opengauss/DSS.git
|
||||
DSS_BRANCH=v5.0.1
|
||||
DSS_BRANCH=master
|
||||
|
||||
echo "clone dss code"
|
||||
if [ -d DSS ]; then
|
||||
|
10
dependency/aws-sdk-cpp/README.txt
Normal file
10
dependency/aws-sdk-cpp/README.txt
Normal file
@ -0,0 +1,10 @@
|
||||
open source target name ��libevent
|
||||
source code repository : product warehouse
|
||||
compile dependency: openssl
|
||||
upgrade open source package method��
|
||||
----|pull command : python $(pwd)../../build/pull_open_source.py "path" "name" "id"
|
||||
|----path : the parent directory name
|
||||
|----name��the package name in product warehouse
|
||||
|----id��pdm version id
|
||||
the compile command : sh build.sh
|
||||
Patch Info:
|
BIN
dependency/aws-sdk-cpp/aws-sdk-cpp-1.11.327.tar.gz
Normal file
BIN
dependency/aws-sdk-cpp/aws-sdk-cpp-1.11.327.tar.gz
Normal file
Binary file not shown.
144
dependency/aws-sdk-cpp/build.sh
Normal file
144
dependency/aws-sdk-cpp/build.sh
Normal file
@ -0,0 +1,144 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) Huawei Technologies Co., Ltd. 2010-2018. All rights reserved.
|
||||
# description: the script that make install libevent
|
||||
# date: 2024-06-08
|
||||
# version: -1.0
|
||||
# history:
|
||||
# 2024-06-08 100 LOC.
|
||||
|
||||
set -e
|
||||
|
||||
LOCAL_PATH=${0}
|
||||
FIRST_CHAR=$(expr substr "$LOCAL_PATH" 1 1)
|
||||
if [ "$FIRST_CHAR" = "/" ]; then
|
||||
LOCAL_PATH=${0}
|
||||
else
|
||||
LOCAL_PATH="$(pwd)/${LOCAL_PATH}"
|
||||
fi
|
||||
|
||||
LOCAL_DIR=$(dirname "${LOCAL_PATH}")
|
||||
CONFIG_FILE_NAME=config.ini
|
||||
BUILD_OPTION=release
|
||||
TAR_FILE_NAME=aws-sdk-cpp-1.11.327.tar.gz
|
||||
SOURCE_CODE_PATH=aws-sdk-cpp-1.11.327
|
||||
LOG_FILE=${LOCAL_DIR}/build_aws.log
|
||||
ROOT_DIR="${LOCAL_DIR}/../../"
|
||||
CURL_LIB="${ROOT_DIR}/output/kernel/dependency/libcurl/comm/lib/libcurl.so"
|
||||
CURL_INCLUDE="${ROOT_DIR}/output/kernel/dependency/libcurl/comm/include"
|
||||
CRYPTO_LIB="${ROOT_DIR}/output/kernel/dependency/openssl/comm/lib/libcrypto.so"
|
||||
CRYPTO_INCLUDE="${ROOT_DIR}/output/kernel/dependency/openssl/comm/include"
|
||||
CRYPTO_STATIC="${ROOT_DIR}/output/kernel/dependency/openssl/comm/lib/libcrypto_static.a"
|
||||
ZLIB_DIR="${ROOT_DIR}/output/kernel/dependency/zlib1.2.11/comm"
|
||||
ZLIB_INCLUDE="${ROOT_DIR}/output/kernel/dependency/zlib1.2.11/comm/include"
|
||||
ZLIB_LIB="${ROOT_DIR}/output/kernel/dependency/zlib1.2.11/comm/lib/libz.so"
|
||||
OPENSSL_DIR="${ROOT_DIR}/output/kernel/dependency/openssl/comm"
|
||||
INSTALL_COMPOENT_PATH_NAME="${ROOT_DIR}/output/kernel/dependency/aws-sdk-cpp"
|
||||
|
||||
log()
|
||||
{
|
||||
echo "[Build libaws-sdk-cpp] "$(date +%y-%m-%d" "%T)": $@"
|
||||
echo "[Build libaws-sdk-cpp] "$(date +%y-%m-%d" "%T)": $@" >> "$LOG_FILE" 2>&1
|
||||
}
|
||||
|
||||
function build_component()
|
||||
{
|
||||
cd ${LOCAL_DIR}
|
||||
if [ -d ${SOURCE_CODE_PATH} ]; then
|
||||
rm -rf ${SOURCE_CODE_PATH}
|
||||
fi
|
||||
mkdir ${SOURCE_CODE_PATH}
|
||||
tar -zxf $TAR_FILE_NAME -C $SOURCE_CODE_PATH --strip-components 1
|
||||
|
||||
cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
die "failed to patch file."
|
||||
fi
|
||||
mkdir -p ${LOCAL_DIR}/${SOURCE_CODE_PATH}/build_comm
|
||||
mkdir -p ${LOCAL_DIR}/install_comm
|
||||
cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}/build_comm
|
||||
cmake .. -DBUILD_ONLY="s3" \
|
||||
-DCMAKE_CXX_FLAGS="-w -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -fstack-protector-strong " \
|
||||
-DCMAKE_C_FLAGS="-w -std=c99 -D_GLIBCXX_USE_CXX11_ABI=0 -fstack-protector-strong " \
|
||||
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,-z,relro,-z,now" \
|
||||
-DCMAKE_SKIP_RPATH=TRUE \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX=${LOCAL_DIR}/install_comm \
|
||||
-DCURL_INCLUDE_DIR=${CURL_INCLUDE} \
|
||||
-DCURL_LIBRARY=${CURL_LIB} \
|
||||
-Dcrypto_INCLUDE_DIR=${CRYPTO_INCLUDE} \
|
||||
-Dcrypto_SHARED_LIBRARY=${CRYPTO_LIB} \
|
||||
-Dcrypto_STATIC_LIBRARY=${CRYPTO_STATIC} \
|
||||
-DZLIB_ROOT=${ZLIB_DIR} \
|
||||
-DZLIB_INCLUDE_DIRS=${ZLIB_INCLUDE} \
|
||||
-DZLIB_LIBRARIES=${ZLIB_LIB} \
|
||||
-DOPENSSL_ROOT_DIR=${OPENSSL_DIR} \
|
||||
-DENABLE_TESTING=OFF
|
||||
make -j4
|
||||
make install
|
||||
cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
|
||||
rm -rf build_comm
|
||||
|
||||
mkdir -p ${LOCAL_DIR}/${SOURCE_CODE_PATH}/build_llt
|
||||
mkdir -p ${LOCAL_DIR}/install_llt
|
||||
cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}/build_llt
|
||||
cmake .. -DBUILD_ONLY="s3" \
|
||||
-DCMAKE_CXX_FLAGS="-w -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -fstack-protector-strong " \
|
||||
-DCMAKE_C_FLAGS="-w -std=c99 -D_GLIBCXX_USE_CXX11_ABI=0 -fstack-protector-strong " \
|
||||
-DCMAKE_SHARED_LINKER_FLAGS="-Wl,-z,relro,-z,now" \
|
||||
-DCMAKE_SKIP_RPATH=TRUE \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX=${LOCAL_DIR}/install_llt \
|
||||
-DCURL_INCLUDE_DIR=${CURL_INCLUDE} \
|
||||
-DCURL_LIBRARY=${CURL_LIB} \
|
||||
-Dcrypto_INCLUDE_DIR=${CRYPTO_INCLUDE} \
|
||||
-Dcrypto_SHARED_LIBRARY=${CRYPTO_LIB} \
|
||||
-Dcrypto_STATIC_LIBRARY=${CRYPTO_STATIC} \
|
||||
-DZLIB_ROOT=${ZLIB_DIR} \
|
||||
-DZLIB_INCLUDE_DIRS=${ZLIB_INCLUDE} \
|
||||
-DZLIB_LIBRARIES=${ZLIB_LIB} \
|
||||
-DOPENSSL_ROOT_DIR=${OPENSSL_DIR} \
|
||||
-DENABLE_TESTING=OFF
|
||||
make -j4
|
||||
make install
|
||||
cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
|
||||
rm -rf build_llt
|
||||
}
|
||||
|
||||
function shrink_component()
|
||||
{
|
||||
mkdir -p ${LOCAL_DIR}/install_comm_dist/lib
|
||||
cp -r ${LOCAL_DIR}/install_comm/include ${LOCAL_DIR}/install_comm_dist
|
||||
cp -r ${LOCAL_DIR}/install_comm/lib64/*\.so* ${LOCAL_DIR}/install_comm_dist/lib
|
||||
|
||||
mkdir -p ${LOCAL_DIR}/install_llt_dist/lib
|
||||
cp -r ${LOCAL_DIR}/install_llt/include ${LOCAL_DIR}/install_llt_dist
|
||||
cp -r ${LOCAL_DIR}/install_llt/lib64/*\.so* ${LOCAL_DIR}/install_llt_dist/lib
|
||||
}
|
||||
|
||||
function dist_component()
|
||||
{
|
||||
mkdir -p ${INSTALL_COMPOENT_PATH_NAME}/comm
|
||||
rm -rf "${INSTALL_COMPOENT_PATH_NAME}"/comm/*
|
||||
cp -r ${LOCAL_DIR}/install_comm_dist/* "${INSTALL_COMPOENT_PATH_NAME}"/comm
|
||||
mkdir -p ${INSTALL_COMPOENT_PATH_NAME}/llt
|
||||
rm -rf "${INSTALL_COMPOENT_PATH_NAME}"/llt/*
|
||||
cp -r ${LOCAL_DIR}/install_llt_dist/* "${INSTALL_COMPOENT_PATH_NAME}"/llt
|
||||
}
|
||||
|
||||
function clean_component()
|
||||
{
|
||||
cd ${LOCAL_DIR}
|
||||
[ -n "${SOURCE_CODE_PATH}" ] && rm -rf "${SOURCE_CODE_PATH}"
|
||||
rm -rf install_*
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
build_component
|
||||
shrink_component
|
||||
dist_component
|
||||
clean_component
|
||||
}
|
||||
|
||||
main
|
5
dependency/aws-sdk-cpp/config.ini
Normal file
5
dependency/aws-sdk-cpp/config.ini
Normal file
@ -0,0 +1,5 @@
|
||||
###############################
|
||||
# aws support
|
||||
###############################
|
||||
binarylibs@event=comm|llt
|
||||
|
@ -23,7 +23,7 @@ tar -zxf $TAR_SOURCE_FILE -C $SOURCE_FILE --strip-components 1
|
||||
cd $SOURCE_FILE
|
||||
CFLAGS='-fstack-protector-all' LDFLAGS='-Wl,-z,relro,-z,now -z,noexecstack' python3 setup.py build
|
||||
|
||||
version_num=("3.6" "3.7" "3.8" "3.9" "3.10")
|
||||
version_num=("3.6" "3.7" "3.8" "3.9" "3.10" "3.11")
|
||||
lib_dir=""
|
||||
for (( i=0;i<${#version_num[*]};i++ ))
|
||||
do
|
||||
@ -47,7 +47,7 @@ if [[ -d "$TARGET_PATH/bcrypt" ]]; then
|
||||
else
|
||||
cp -r build/lib*/* $TARGET_PATH
|
||||
mkdir -p $TARGET_PATH/bcrypt/$lib_dir
|
||||
cp $TARGET_PATH/bcrypt/_bcrypt.abi3.so $TARGET_PATH/bcrypt/$lib_dir
|
||||
mv $TARGET_PATH/bcrypt/_bcrypt.abi3.so $TARGET_PATH/bcrypt/$lib_dir
|
||||
fi
|
||||
|
||||
cp $ROOT_DIR/_bcrypt.py $TARGET_PATH/bcrypt/
|
||||
cp $ROOT_DIR/_bcrypt.py $TARGET_PATH/bcrypt/
|
@ -23,7 +23,12 @@ function build_component()
|
||||
fi
|
||||
|
||||
# Compatible with python3 compilation
|
||||
sed -i "s/include\/python\$(version)/include\/python\$(version)m/g" tools/build/src/tools/python.jam
|
||||
python_version=`python3 -V | awk -F ' ' '{print $2}' |awk -F '.' -v OFS='.' '{print $1,$2}'`
|
||||
if [ "$python_version" == "3.11" ]; then
|
||||
sed -i "s/include\/python\$(version)/include\/python\$(version)/g" tools/build/src/tools/python.jam
|
||||
else
|
||||
sed -i "s/include\/python\$(version)/include\/python\$(version)m/g" tools/build/src/tools/python.jam
|
||||
fi
|
||||
|
||||
chmod +x bootstrap.sh
|
||||
chmod +x ./tools/build/src/engine/build.sh
|
||||
|
Binary file not shown.
@ -27,8 +27,6 @@ start_tm=$(date +%s%N)
|
||||
cd $(pwd)/../jemalloc
|
||||
if [ "$ARCH"x != "loongarch64"x ];then
|
||||
python3 build.py -m all -t "release|debug" -f jemalloc-5.2.1.tar.gz >>../build/build_result.log
|
||||
else
|
||||
python3 build.py -m all -t "release|debug" -f jemalloc-5.3.0.tar.gz >>../build/build_result.log
|
||||
fi
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
@ -43,7 +41,7 @@ echo "[libcgroup] is " $use_tm
|
||||
echo ------------------------------numactl----------------------------------------------------
|
||||
start_tm=$(date +%s%N)
|
||||
cd $(pwd)/../numactl
|
||||
python3 build.py -m all -t "comm|llt" -f numactl-2.0.14.tar.gz >>../build/build_result.log
|
||||
python3 build.py -m all -t "comm|llt" -f numactl-2.0.16.tar.gz >>../build/build_result.log
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
echo "[numactl] is " $use_tm
|
||||
@ -94,7 +92,7 @@ echo "[six] $use_tm"
|
||||
echo -------------------------------ipaddres--------------------------------------------------
|
||||
start_tm=$(date +%s%N)
|
||||
cd $(pwd)/../ipaddress
|
||||
sh build.sh >>../build/demo.log
|
||||
sh build.sh >>../build/build_result.log
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
echo "[ipaddress] $use_tm"
|
||||
@ -137,6 +135,13 @@ sh build.sh >>../build/build_result.log
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
echo "[bottle] $use_tm"
|
||||
echo ---------------------------------tornado--------------------------------------------------
|
||||
start_tm=$(date +%s%N)
|
||||
cd $(pwd)/../tornado
|
||||
sh build.sh >>../build/build_result.log
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
echo "[tornado] $use_tm"
|
||||
echo -------------------------------------dmlc-core----------------------------------------------
|
||||
start_tm=$(date +%s%N)
|
||||
cd $(pwd)/../dmlc-core
|
||||
@ -340,6 +345,13 @@ sh build.sh >> ../build/build_result.log
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
echo "[libevent] $use_tm"
|
||||
echo ---------------------------------------aws-sdk-cpp------------------------------------------
|
||||
start_tm=$(date +%s%N)
|
||||
cd $(pwd)/../aws-sdk-cpp
|
||||
sh build.sh >> ../build/build_result.log
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
echo "[aws-sdk-cpp] $use_tm"
|
||||
|
||||
# only copy
|
||||
echo ----------------------------------------etcd-------------------------------------------
|
||||
|
@ -18,9 +18,9 @@ PLATFORM="$(bash ${ROOT_DIR}/build/get_PlatForm_str.sh)"
|
||||
|
||||
echo --------------------------------openssl-------------------------------------------------
|
||||
start_tm=$(date +%s%N)
|
||||
[ -f demo.log ] && rm -rf demo.log
|
||||
[ -f build_result.log ] && rm -rf build_result.log
|
||||
cd $(pwd)/../openssl
|
||||
python3 build.py -m all -f openssl-OpenSSL_1_1_1n.tar.gz -t "comm|llt" >>../build/demo.log
|
||||
python3 build.py -m all -f openssl-OpenSSL_1_1_1n.tar.gz -t "comm|llt" >>../build/build_result.log
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
echo "[openssl] $use_tm"
|
||||
@ -44,7 +44,7 @@ echo "[six] $use_tm"
|
||||
echo -------------------------------ipaddres--------------------------------------------------
|
||||
start_tm=$(date +%s%N)
|
||||
cd $(pwd)/../ipaddress
|
||||
sh build.sh >>../build/demo.log
|
||||
sh build.sh >>../build/build_result.log
|
||||
end_tm=$(date +%s%N)
|
||||
use_tm=$(echo $end_tm $start_tm | awk '{ print ($1 - $2) / 1000000000}' | xargs printf "%.2f")
|
||||
echo "[ipaddress] $use_tm"
|
||||
|
12
dependency/cJSON/CVE-2024-31755.patch
Normal file
12
dependency/cJSON/CVE-2024-31755.patch
Normal file
@ -0,0 +1,12 @@
|
||||
diff -Naur a/cJSON.c b/cJSON.c
|
||||
--- a/cJSON.c 2024-05-27 11:17:06.041240225 +0800
|
||||
+++ b/cJSON.c 2024-05-27 11:19:35.927227504 +0800
|
||||
@@ -406,7 +406,7 @@
|
||||
return NULL;
|
||||
}
|
||||
/* return NULL if the object is corrupted */
|
||||
- if (object->valuestring == NULL)
|
||||
+ if (object->valuestring == NULL || valuestring == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
@ -38,6 +38,9 @@ function main()
|
||||
fi
|
||||
mkdir $SOURCE_CODE_PATH
|
||||
tar -zxf $TAR_FILE_NAME -C $SOURCE_CODE_PATH --strip-components 1
|
||||
cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
|
||||
patch -p1 < ../CVE-2023-50471andCVE-2023-50472.patch
|
||||
patch -p1 < ../CVE-2024-31755.patch
|
||||
case "${BUILD_OPTION}" in
|
||||
build)
|
||||
build_component
|
||||
|
@ -8,7 +8,7 @@ export LD_LIBRARY_PATH=$TARGET_PATH:$LD_LIBRARY_PATH:/usr/lib64
|
||||
export PATH=$TARGET_PATH:$PATH
|
||||
export PYTHONPATH=$TARGET_PATH:$LIBRARY_PATH
|
||||
|
||||
version_list=("3.6" "3.7" "3.8" "3.9" "3.10")
|
||||
version_list=("3.6" "3.7" "3.8" "3.9" "3.10" "3.11")
|
||||
python_version=`python3 -V | awk -F ' ' '{print $2}' | awk -F '.' -v OFS='.' '{print $1,$2}'`
|
||||
|
||||
TAR_SOURCE_FILE=cffi-1.15.0.tar.gz
|
||||
|
@ -17,7 +17,7 @@ if [ -d ${SOURCE_FILE} ]; then
|
||||
fi
|
||||
mkdir ${SOURCE_FILE}
|
||||
|
||||
version_num=("3.6" "3.7" "3.8" "3.9" "3.10")
|
||||
version_num=("3.6" "3.7" "3.8" "3.9" "3.10" "3.11")
|
||||
lib_dir=""
|
||||
for (( i=0;i<${#version_num[*]};i++ ))
|
||||
do
|
||||
@ -40,8 +40,8 @@ if [[ -d "$TARGET_PATH/cryptography/hazmat/bindings" ]]; then
|
||||
else
|
||||
cp -r build/lib*/* $TARGET_PATH
|
||||
mkdir -p $TARGET_PATH/cryptography/hazmat/bindings/$lib_dir
|
||||
cp $TARGET_PATH/cryptography/hazmat/bindings/*.so $TARGET_PATH/cryptography/hazmat/bindings/$lib_dir
|
||||
mv $TARGET_PATH/cryptography/hazmat/bindings/*.so $TARGET_PATH/cryptography/hazmat/bindings/$lib_dir
|
||||
fi
|
||||
|
||||
cp $ROOT_DIR/_openssl.py $TARGET_PATH/cryptography/hazmat/bindings/
|
||||
cp $ROOT_DIR/_padding.py $TARGET_PATH/cryptography/hazmat/bindings/
|
||||
cp $ROOT_DIR/_padding.py $TARGET_PATH/cryptography/hazmat/bindings/
|
@ -25,7 +25,7 @@ g_PATH=build
|
||||
NGHTTP_DIR=${TRUNK_DIR}/dependency/nghttp2/install_comm
|
||||
LIBXML2_DIR=${TRUNK_DIR}/dependency/libxml2/install_comm
|
||||
CURL_DIR=${TRUNK_DIR}/output/kernel/dependency/libcurl/comm
|
||||
OPENSSL_DIR=${TRUNK_DIR}/output/kernrl/dependency/openssl/comm
|
||||
OPENSSL_DIR=${TRUNK_DIR}/output/kernel/dependency/openssl/comm
|
||||
PCRE_DIR=${TRUNK_DIR}/dependency/pcre/install_comm
|
||||
LIBICONV_DIR=${TRUNK_DIR}/dependency/libiconv/install_comm
|
||||
SECUREC_DIR=${TRUNK_DIR}/output/kernel/platform/Huawei_Secure_C/comm
|
||||
|
@ -5,14 +5,12 @@ mkdir -p $(pwd)/../../output/install_tools
|
||||
export TARGET_PATH=$(pwd)/../../output/install_tools/
|
||||
export LD_LIBRARY_PATH=$TARGET_PATH:$LD_LIBRARY_PATH
|
||||
export PATH=$TARGET_PATH:$PATH
|
||||
TAR_SOURCE_FILE=idna-2.10.tar.gz
|
||||
SOURCE_FILE=idna-2.10
|
||||
TAR_SOURCE_FILE=idna-3.7.tar.gz
|
||||
SOURCE_FILE=idna-3.7
|
||||
if [ -d ${SOURCE_FILE} ]; then
|
||||
rm -rf ${SOURCE_FILE}
|
||||
fi
|
||||
mkdir ${SOURCE_FILE}
|
||||
tar -zxf $TAR_SOURCE_FILE -C $SOURCE_FILE --strip-components 1
|
||||
cd $SOURCE_FILE
|
||||
python3 setup.py build
|
||||
python3 setup.py install --user
|
||||
cp -r build/lib*/* $TARGET_PATH
|
||||
cp -r idna $TARGET_PATH
|
||||
|
BIN
dependency/idna/idna-3.7.tar.gz
Normal file
BIN
dependency/idna/idna-3.7.tar.gz
Normal file
Binary file not shown.
@ -10,6 +10,7 @@ TAR_SOURCE_FILE=ipaddress-1.0.22.tar.gz
|
||||
SOURCE_FILE=ipaddress-1.0.22
|
||||
tar zxvf $TAR_SOURCE_FILE
|
||||
cd $SOURCE_FILE
|
||||
patch -p1 < ../ipaddress-1.0.patch
|
||||
python3 setup.py build
|
||||
python3 setup.py install --user
|
||||
cp -r build/lib*/* $TARGET_PATH
|
||||
|
20
dependency/ipaddress/ipaddress-1.0.patch
Normal file
20
dependency/ipaddress/ipaddress-1.0.patch
Normal file
@ -0,0 +1,20 @@
|
||||
diff -crN '--exclude=.git' '--exclude=.gitee' '--exclude=.vscode' ipaddress-1.0.22/ipaddress.py ipaddress-1.0.22-v1.0/ipaddress.py
|
||||
*** ipaddress-1.0.22/ipaddress.py 2018-04-16 02:00:41.000000000 +0800
|
||||
--- ipaddress-1.0.22-v1.0/ipaddress.py 2023-10-26 19:51:58.044810776 +0800
|
||||
***************
|
||||
*** 1103,1109 ****
|
||||
try:
|
||||
# Always false if one is v4 and the other is v6.
|
||||
if a._version != b._version:
|
||||
! raise TypeError("%s and %s are not of the same version" (a, b))
|
||||
return (b.network_address <= a.network_address and
|
||||
b.broadcast_address >= a.broadcast_address)
|
||||
except AttributeError:
|
||||
--- 1103,1109 ----
|
||||
try:
|
||||
# Always false if one is v4 and the other is v6.
|
||||
if a._version != b._version:
|
||||
! raise TypeError("%s and %s are not of the same version" % (a, b))
|
||||
return (b.network_address <= a.network_address and
|
||||
b.broadcast_address >= a.broadcast_address)
|
||||
except AttributeError:
|
Binary file not shown.
@ -0,0 +1,171 @@
|
||||
From 548da160b52b25a106e9f6077d6a42c2c049586c Mon Sep 17 00:00:00 2001
|
||||
From: Greg Hudson <ghudson@mit.edu>
|
||||
Date: Tue, 7 Mar 2023 00:19:33 -0500
|
||||
Subject: [PATCH] Add a simple DER support header
|
||||
|
||||
Reference: https://github.com/krb5/krb5/commit/548da160b52b25a106e9f6077d6a42c2c049586c
|
||||
Conflict: NA
|
||||
|
||||
---
|
||||
src/include/k5-der.h | 149 +++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 149 insertions(+)
|
||||
create mode 100644 src/include/k5-der.h
|
||||
|
||||
diff --git a/src/include/k5-der.h b/src/include/k5-der.h
|
||||
new file mode 100644
|
||||
index 0000000..b8371d9
|
||||
--- /dev/null
|
||||
+++ b/src/include/k5-der.h
|
||||
@@ -0,0 +1,149 @@
|
||||
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
+/* include/k5-der.h - Distinguished Encoding Rules (DER) declarations */
|
||||
+/*
|
||||
+ * Copyright (C) 2023 by the Massachusetts Institute of Technology.
|
||||
+ * All rights reserved.
|
||||
+ *
|
||||
+ * Redistribution and use in source and binary forms, with or without
|
||||
+ * modification, are permitted provided that the following conditions
|
||||
+ * are met:
|
||||
+ *
|
||||
+ * * Redistributions of source code must retain the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer.
|
||||
+ *
|
||||
+ * * Redistributions in binary form must reproduce the above copyright
|
||||
+ * notice, this list of conditions and the following disclaimer in
|
||||
+ * the documentation and/or other materials provided with the
|
||||
+ * distribution.
|
||||
+ *
|
||||
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
+ */
|
||||
+
|
||||
+/*
|
||||
+ * Most ASN.1 encoding and decoding is done using the table-driven framework in
|
||||
+ * libkrb5. When that is not an option, these helpers can be used to encode
|
||||
+ * and decode simple types.
|
||||
+ */
|
||||
+
|
||||
+#ifndef K5_DER_H
|
||||
+#define K5_DER_H
|
||||
+
|
||||
+#include <stdint.h>
|
||||
+#include <stdbool.h>
|
||||
+#include "k5-buf.h"
|
||||
+#include "k5-input.h"
|
||||
+
|
||||
+/* Return the number of bytes needed to encode len as a DER encoding length. */
|
||||
+static inline size_t
|
||||
+k5_der_len_len(size_t len)
|
||||
+{
|
||||
+ size_t llen;
|
||||
+
|
||||
+ if (len < 128)
|
||||
+ return 1;
|
||||
+ llen = 1;
|
||||
+ while (len > 0) {
|
||||
+ len >>= 8;
|
||||
+ llen++;
|
||||
+ }
|
||||
+ return llen;
|
||||
+}
|
||||
+
|
||||
+/* Return the number of bytes needed to encode a DER value (with identifier
|
||||
+ * byte and length) for a given contents length. */
|
||||
+static inline size_t
|
||||
+k5_der_value_len(size_t contents_len)
|
||||
+{
|
||||
+ return 1 + k5_der_len_len(contents_len) + contents_len;
|
||||
+}
|
||||
+
|
||||
+/* Add a DER identifier byte (composed by the caller, including the ASN.1
|
||||
+ * class, tag, and constructed bit) and length. */
|
||||
+static inline void
|
||||
+k5_der_add_taglen(struct k5buf *buf, uint8_t idbyte, size_t len)
|
||||
+{
|
||||
+ uint8_t *p;
|
||||
+ size_t llen = k5_der_len_len(len);
|
||||
+
|
||||
+ p = k5_buf_get_space(buf, 1 + llen);
|
||||
+ if (p == NULL)
|
||||
+ return;
|
||||
+ *p++ = idbyte;
|
||||
+ if (len < 128) {
|
||||
+ *p = len;
|
||||
+ } else {
|
||||
+ *p = 0x80 | (llen - 1);
|
||||
+ /* Encode the length bytes backwards so the most significant byte is
|
||||
+ * first. */
|
||||
+ p += llen;
|
||||
+ while (len > 0) {
|
||||
+ *--p = len & 0xFF;
|
||||
+ len >>= 8;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/* Add a DER value (identifier byte, length, and contents). */
|
||||
+static inline void
|
||||
+k5_der_add_value(struct k5buf *buf, uint8_t idbyte, const void *contents,
|
||||
+ size_t len)
|
||||
+{
|
||||
+ k5_der_add_taglen(buf, idbyte, len);
|
||||
+ k5_buf_add_len(buf, contents, len);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * If the next byte in in matches idbyte and the subsequent DER length is
|
||||
+ * valid, advance in past the value, set *contents_out to the value contents,
|
||||
+ * and return true. Otherwise return false. Only set an error on in if the
|
||||
+ * next bytes matches idbyte but the ensuing length is invalid. contents_out
|
||||
+ * may be aliased to in; it will only be written to on successful decoding of a
|
||||
+ * value.
|
||||
+ */
|
||||
+static inline bool
|
||||
+k5_der_get_value(struct k5input *in, uint8_t idbyte,
|
||||
+ struct k5input *contents_out)
|
||||
+{
|
||||
+ uint8_t lenbyte, i;
|
||||
+ size_t len;
|
||||
+ const void *bytes;
|
||||
+
|
||||
+ /* Do nothing if in is empty or the next byte doesn't match idbyte. */
|
||||
+ if (in->status || in->len == 0 || *in->ptr != idbyte)
|
||||
+ return false;
|
||||
+
|
||||
+ /* Advance past the identifier byte and decode the length. */
|
||||
+ (void)k5_input_get_byte(in);
|
||||
+ lenbyte = k5_input_get_byte(in);
|
||||
+ if (lenbyte < 128) {
|
||||
+ len = lenbyte;
|
||||
+ } else {
|
||||
+ len = 0;
|
||||
+ for (i = 0; i < (lenbyte & 0x7F); i++) {
|
||||
+ if (len > (SIZE_MAX >> 8)) {
|
||||
+ k5_input_set_status(in, EOVERFLOW);
|
||||
+ return false;
|
||||
+ }
|
||||
+ len = (len << 8) | k5_input_get_byte(in);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ bytes = k5_input_get_bytes(in, len);
|
||||
+ if (bytes == NULL)
|
||||
+ return false;
|
||||
+ k5_input_init(contents_out, bytes, len);
|
||||
+ return true;
|
||||
+}
|
||||
+
|
||||
+#endif /* K5_DER_H */
|
||||
--
|
||||
2.33.0
|
||||
|
@ -0,0 +1,536 @@
|
||||
From b0a2f8a5365f2eec3e27d78907de9f9d2c80505a Mon Sep 17 00:00:00 2001
|
||||
From: Greg Hudson <ghudson@mit.edu>
|
||||
Date: Fri, 14 Jun 2024 10:56:12 -0400
|
||||
Subject: [PATCH] Fix vulnerabilities in GSS message token handling
|
||||
|
||||
In gss_krb5int_unseal_token_v3() and gss_krb5int_unseal_v3_iov(),
|
||||
verify the Extra Count field of CFX wrap tokens against the encrypted
|
||||
header. Reported by Jacob Champion.
|
||||
|
||||
In gss_krb5int_unseal_token_v3(), check for a decrypted plaintext
|
||||
length too short to contain the encrypted header and extra count
|
||||
bytes. Reported by Jacob Champion.
|
||||
|
||||
In kg_unseal_iov_token(), separately track the header IOV length and
|
||||
complete token length when parsing the token's ASN.1 wrapper. This
|
||||
fix contains modified versions of functions from k5-der.h and
|
||||
util_token.c; this duplication will be cleaned up in a future commit.
|
||||
|
||||
CVE-2024-37370:
|
||||
|
||||
In MIT krb5 release 1.3 and later, an attacker can modify the
|
||||
plaintext Extra Count field of a confidential GSS krb5 wrap token,
|
||||
causing the unwrapped token to appear truncated to the application.
|
||||
|
||||
CVE-2024-37371:
|
||||
|
||||
In MIT krb5 release 1.3 and later, an attacker can cause invalid
|
||||
memory reads by sending message tokens with invalid length fields.
|
||||
|
||||
ticket: 9128 (new)
|
||||
tags: pullup
|
||||
target_version: 1.21-next
|
||||
|
||||
Reference: https://github.com/krb5/krb5/commit/b0a2f8a5365f2eec3e27d78907de9f9d2c80505a
|
||||
Conflict: src/tests/gssapi/t_invalid.c
|
||||
|
||||
---
|
||||
src/lib/gssapi/krb5/k5sealv3.c | 5 +
|
||||
src/lib/gssapi/krb5/k5sealv3iov.c | 3 +-
|
||||
src/lib/gssapi/krb5/k5unsealiov.c | 80 +++++++++-
|
||||
src/tests/gssapi/t_invalid.c | 233 +++++++++++++++++++++++++-----
|
||||
4 files changed, 275 insertions(+), 46 deletions(-)
|
||||
|
||||
diff --git a/src/lib/gssapi/krb5/k5sealv3.c b/src/lib/gssapi/krb5/k5sealv3.c
|
||||
index e881eee..d3210c1 100644
|
||||
--- a/src/lib/gssapi/krb5/k5sealv3.c
|
||||
+++ b/src/lib/gssapi/krb5/k5sealv3.c
|
||||
@@ -400,10 +400,15 @@ gss_krb5int_unseal_token_v3(krb5_context *contextptr,
|
||||
/* Don't use bodysize here! Use the fact that
|
||||
cipher.ciphertext.length has been adjusted to the
|
||||
correct length. */
|
||||
+ if (plain.length < 16 + ec) {
|
||||
+ free(plain.data);
|
||||
+ goto defective;
|
||||
+ }
|
||||
althdr = (unsigned char *)plain.data + plain.length - 16;
|
||||
if (load_16_be(althdr) != KG2_TOK_WRAP_MSG
|
||||
|| althdr[2] != ptr[2]
|
||||
|| althdr[3] != ptr[3]
|
||||
+ || load_16_be(althdr+4) != ec
|
||||
|| memcmp(althdr+8, ptr+8, 8)) {
|
||||
free(plain.data);
|
||||
goto defective;
|
||||
diff --git a/src/lib/gssapi/krb5/k5sealv3iov.c b/src/lib/gssapi/krb5/k5sealv3iov.c
|
||||
index 333ee12..f8e90c3 100644
|
||||
--- a/src/lib/gssapi/krb5/k5sealv3iov.c
|
||||
+++ b/src/lib/gssapi/krb5/k5sealv3iov.c
|
||||
@@ -402,9 +402,10 @@ gss_krb5int_unseal_v3_iov(krb5_context context,
|
||||
if (load_16_be(althdr) != KG2_TOK_WRAP_MSG
|
||||
|| althdr[2] != ptr[2]
|
||||
|| althdr[3] != ptr[3]
|
||||
+ || load_16_be(althdr + 4) != ec
|
||||
|| memcmp(althdr + 8, ptr + 8, 8) != 0) {
|
||||
*minor_status = 0;
|
||||
- return GSS_S_BAD_SIG;
|
||||
+ return GSS_S_DEFECTIVE_TOKEN;
|
||||
}
|
||||
} else {
|
||||
/* Verify checksum: note EC is checksum size here, not padding */
|
||||
diff --git a/src/lib/gssapi/krb5/k5unsealiov.c b/src/lib/gssapi/krb5/k5unsealiov.c
|
||||
index 3ce2a90..6a6585d 100644
|
||||
--- a/src/lib/gssapi/krb5/k5unsealiov.c
|
||||
+++ b/src/lib/gssapi/krb5/k5unsealiov.c
|
||||
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "k5-int.h"
|
||||
+#include "k5-der.h"
|
||||
#include "gssapiP_krb5.h"
|
||||
|
||||
static OM_uint32
|
||||
@@ -247,6 +248,73 @@ cleanup:
|
||||
return retval;
|
||||
}
|
||||
|
||||
+/* Similar to k5_der_get_value(), but output an unchecked content length
|
||||
+ * instead of a k5input containing the contents. */
|
||||
+static inline bool
|
||||
+get_der_tag(struct k5input *in, uint8_t idbyte, size_t *len_out)
|
||||
+{
|
||||
+ uint8_t lenbyte, i;
|
||||
+ size_t len;
|
||||
+
|
||||
+ /* Do nothing if in is empty or the next byte doesn't match idbyte. */
|
||||
+ if (in->status || in->len == 0 || *in->ptr != idbyte)
|
||||
+ return false;
|
||||
+
|
||||
+ /* Advance past the identifier byte and decode the length. */
|
||||
+ (void)k5_input_get_byte(in);
|
||||
+ lenbyte = k5_input_get_byte(in);
|
||||
+ if (lenbyte < 128) {
|
||||
+ len = lenbyte;
|
||||
+ } else {
|
||||
+ len = 0;
|
||||
+ for (i = 0; i < (lenbyte & 0x7F); i++) {
|
||||
+ if (len > (SIZE_MAX >> 8)) {
|
||||
+ k5_input_set_status(in, EOVERFLOW);
|
||||
+ return false;
|
||||
+ }
|
||||
+ len = (len << 8) | k5_input_get_byte(in);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (in->status)
|
||||
+ return false;
|
||||
+
|
||||
+ *len_out = len;
|
||||
+ return true;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Similar to g_verify_token_header() without toktype or flags, but do not read
|
||||
+ * more than *header_len bytes of ASN.1 wrapper, and on output set *header_len
|
||||
+ * to the remaining number of header bytes. Verify the outer DER tag's length
|
||||
+ * against token_len, which may be larger (but not smaller) than *header_len.
|
||||
+ */
|
||||
+static gss_int32
|
||||
+verify_detached_wrapper(const gss_OID_desc *mech, size_t *header_len,
|
||||
+ uint8_t **header_in, size_t token_len)
|
||||
+{
|
||||
+ struct k5input in, mech_der;
|
||||
+ gss_OID_desc toid;
|
||||
+ size_t len;
|
||||
+
|
||||
+ k5_input_init(&in, *header_in, *header_len);
|
||||
+
|
||||
+ if (get_der_tag(&in, 0x60, &len)) {
|
||||
+ if (len != token_len - (in.ptr - *header_in))
|
||||
+ return G_BAD_TOK_HEADER;
|
||||
+ if (!k5_der_get_value(&in, 0x06, &mech_der))
|
||||
+ return G_BAD_TOK_HEADER;
|
||||
+ toid.elements = (uint8_t *)mech_der.ptr;
|
||||
+ toid.length = mech_der.len;
|
||||
+ if (!g_OID_equal(&toid, mech))
|
||||
+ return G_WRONG_MECH;
|
||||
+ }
|
||||
+
|
||||
+ *header_in = (uint8_t *)in.ptr;
|
||||
+ *header_len = in.len;
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
/*
|
||||
* Caller must provide TOKEN | DATA | PADDING | TRAILER, except
|
||||
* for DCE in which case it can just provide TOKEN | DATA (must
|
||||
@@ -267,8 +335,7 @@ kg_unseal_iov_token(OM_uint32 *minor_status,
|
||||
gss_iov_buffer_t header;
|
||||
gss_iov_buffer_t padding;
|
||||
gss_iov_buffer_t trailer;
|
||||
- size_t input_length;
|
||||
- unsigned int bodysize;
|
||||
+ size_t input_length, hlen;
|
||||
int toktype2;
|
||||
|
||||
header = kg_locate_header_iov(iov, iov_count, toktype);
|
||||
@@ -298,15 +365,14 @@ kg_unseal_iov_token(OM_uint32 *minor_status,
|
||||
input_length += trailer->buffer.length;
|
||||
}
|
||||
|
||||
- code = g_verify_token_header(ctx->mech_used,
|
||||
- &bodysize, &ptr, -1,
|
||||
- input_length, 0);
|
||||
+ hlen = header->buffer.length;
|
||||
+ code = verify_detached_wrapper(ctx->mech_used, &hlen, &ptr, input_length);
|
||||
if (code != 0) {
|
||||
*minor_status = code;
|
||||
return GSS_S_DEFECTIVE_TOKEN;
|
||||
}
|
||||
|
||||
- if (bodysize < 2) {
|
||||
+ if (hlen < 2) {
|
||||
*minor_status = (OM_uint32)G_BAD_TOK_HEADER;
|
||||
return GSS_S_DEFECTIVE_TOKEN;
|
||||
}
|
||||
@@ -314,7 +380,7 @@ kg_unseal_iov_token(OM_uint32 *minor_status,
|
||||
toktype2 = load_16_be(ptr);
|
||||
|
||||
ptr += 2;
|
||||
- bodysize -= 2;
|
||||
+ hlen -= 2;
|
||||
|
||||
switch (toktype2) {
|
||||
case KG2_TOK_MIC_MSG:
|
||||
diff --git a/src/tests/gssapi/t_invalid.c b/src/tests/gssapi/t_invalid.c
|
||||
index fb8fe55..d1f019f 100644
|
||||
--- a/src/tests/gssapi/t_invalid.c
|
||||
+++ b/src/tests/gssapi/t_invalid.c
|
||||
@@ -36,31 +36,41 @@
|
||||
*
|
||||
* 1. A pre-CFX wrap or MIC token processed with a CFX-only context causes a
|
||||
* null pointer dereference. (The token must use SEAL_ALG_NONE or it will
|
||||
- * be rejected.)
|
||||
+ * be rejected.) This vulnerability also applies to IOV unwrap.
|
||||
*
|
||||
- * 2. A pre-CFX wrap or MIC token with fewer than 24 bytes after the ASN.1
|
||||
+ * 2. A CFX wrap token with a different value of EC between the plaintext and
|
||||
+ * encrypted copies will be erroneously accepted, which allows a message
|
||||
+ * truncation attack. This vulnerability also applies to IOV unwrap.
|
||||
+ *
|
||||
+ * 3. A CFX wrap token with a plaintext length fewer than 16 bytes causes an
|
||||
+ * access before the beginning of the input buffer, possibly leading to a
|
||||
+ * crash.
|
||||
+ *
|
||||
+ * 4. A CFX wrap token with a plaintext EC value greater than the plaintext
|
||||
+ * length - 16 causes an integer underflow when computing the result length,
|
||||
+ * likely causing a crash.
|
||||
+ *
|
||||
+ * 5. An IOV unwrap operation will overrun the header buffer if an ASN.1
|
||||
+ * wrapper longer than the header buffer is present.
|
||||
+ *
|
||||
+ * 6. A pre-CFX wrap or MIC token with fewer than 24 bytes after the ASN.1
|
||||
* header causes an input buffer overrun, usually leading to either a segv
|
||||
* or a GSS_S_DEFECTIVE_TOKEN error due to garbage algorithm, filler, or
|
||||
- * sequence number values.
|
||||
+ * sequence number values. This vulnerability also applies to IOV unwrap.
|
||||
*
|
||||
- * 3. A pre-CFX wrap token with fewer than 16 + cksumlen bytes after the ASN.1
|
||||
+ * 7. A pre-CFX wrap token with fewer than 16 + cksumlen bytes after the ASN.1
|
||||
* header causes an integer underflow when computing the ciphertext length,
|
||||
* leading to an allocation error on 32-bit platforms or a segv on 64-bit
|
||||
* platforms. A pre-CFX MIC token of this size causes an input buffer
|
||||
* overrun when comparing the checksum, perhaps leading to a segv.
|
||||
*
|
||||
- * 4. A pre-CFX wrap token with fewer than conflen + padlen bytes in the
|
||||
+ * 8. A pre-CFX wrap token with fewer than conflen + padlen bytes in the
|
||||
* ciphertext (where padlen is the last byte of the decrypted ciphertext)
|
||||
* causes an integer underflow when computing the original message length,
|
||||
* leading to an allocation error.
|
||||
*
|
||||
- * 5. In the mechglue, truncated encapsulation in the initial context token can
|
||||
+ * 9. In the mechglue, truncated encapsulation in the initial context token can
|
||||
* cause input buffer overruns in gss_accept_sec_context().
|
||||
- *
|
||||
- * Vulnerabilities #1 and #2 also apply to IOV unwrap, although tokens with
|
||||
- * fewer than 16 bytes after the ASN.1 header will be rejected.
|
||||
- * Vulnerabilities #2 and #5 can only be robustly detected using a
|
||||
- * memory-checking environment such as valgrind.
|
||||
*/
|
||||
|
||||
#include "k5-int.h"
|
||||
@@ -98,16 +108,24 @@ struct test {
|
||||
};
|
||||
|
||||
/* Fake up enough of a CFX GSS context for gss_unwrap, using an AES key. */
|
||||
+static void *
|
||||
+ealloc(size_t len)
|
||||
+{
|
||||
+ void *ptr = calloc(len, 1);
|
||||
+
|
||||
+ if (ptr == NULL)
|
||||
+ abort();
|
||||
+ return ptr;
|
||||
+}
|
||||
+
|
||||
+/* Fake up enough of a CFX GSS context for gss_unwrap, using an AES key.
|
||||
+ * The context takes ownership of subkey. */
|
||||
static gss_ctx_id_t
|
||||
-make_fake_cfx_context()
|
||||
+make_fake_cfx_context(krb5_key subkey)
|
||||
{
|
||||
gss_union_ctx_id_t uctx;
|
||||
krb5_gss_ctx_id_t kgctx;
|
||||
- krb5_keyblock kb;
|
||||
-
|
||||
- kgctx = calloc(1, sizeof(*kgctx));
|
||||
- if (kgctx == NULL)
|
||||
- abort();
|
||||
+ kgctx = ealloc(sizeof(*kgctx));
|
||||
kgctx->established = 1;
|
||||
kgctx->proto = 1;
|
||||
if (g_seqstate_init(&kgctx->seqstate, 0, 0, 0, 0) != 0)
|
||||
@@ -116,15 +134,10 @@ make_fake_cfx_context()
|
||||
kgctx->sealalg = -1;
|
||||
kgctx->signalg = -1;
|
||||
|
||||
- kb.enctype = ENCTYPE_AES128_CTS_HMAC_SHA1_96;
|
||||
- kb.length = 16;
|
||||
- kb.contents = (unsigned char *)"1234567887654321";
|
||||
- if (krb5_k_create_key(NULL, &kb, &kgctx->subkey) != 0)
|
||||
- abort();
|
||||
+ kgctx->subkey = subkey;
|
||||
+ kgctx->cksumtype = CKSUMTYPE_HMAC_SHA1_96_AES128;
|
||||
|
||||
- uctx = calloc(1, sizeof(*uctx));
|
||||
- if (uctx == NULL)
|
||||
- abort();
|
||||
+ uctx = ealloc(sizeof(*uctx));
|
||||
uctx->mech_type = &mech_krb5;
|
||||
uctx->internal_ctx_id = (gss_ctx_id_t)kgctx;
|
||||
return (gss_ctx_id_t)uctx;
|
||||
@@ -138,9 +151,7 @@ make_fake_context(const struct test *test)
|
||||
krb5_gss_ctx_id_t kgctx;
|
||||
krb5_keyblock kb;
|
||||
|
||||
- kgctx = calloc(1, sizeof(*kgctx));
|
||||
- if (kgctx == NULL)
|
||||
- abort();
|
||||
+ kgctx = ealloc(sizeof(*kgctx));
|
||||
kgctx->established = 1;
|
||||
if (g_seqstate_init(&kgctx->seqstate, 0, 0, 0, 0) != 0)
|
||||
abort();
|
||||
@@ -162,9 +173,7 @@ make_fake_context(const struct test *test)
|
||||
if (krb5_k_create_key(NULL, &kb, &kgctx->enc) != 0)
|
||||
abort();
|
||||
|
||||
- uctx = calloc(1, sizeof(*uctx));
|
||||
- if (uctx == NULL)
|
||||
- abort();
|
||||
+ uctx = ealloc(sizeof(*uctx));
|
||||
uctx->mech_type = &mech_krb5;
|
||||
uctx->internal_ctx_id = (gss_ctx_id_t)kgctx;
|
||||
return (gss_ctx_id_t)uctx;
|
||||
@@ -194,9 +203,7 @@ make_token(unsigned char *token, size_t len, gss_buffer_t out)
|
||||
|
||||
assert(mech_krb5.length == 9);
|
||||
assert(len + 11 < 128);
|
||||
- wrapped = malloc(len + 13);
|
||||
- if (wrapped == NULL)
|
||||
- abort();
|
||||
+ wrapped = ealloc(len + 13);
|
||||
wrapped[0] = 0x60;
|
||||
wrapped[1] = len + 11;
|
||||
wrapped[2] = 0x06;
|
||||
@@ -207,6 +214,18 @@ make_token(unsigned char *token, size_t len, gss_buffer_t out)
|
||||
out->value = wrapped;
|
||||
}
|
||||
|
||||
+/* Create a 16-byte header for a CFX confidential wrap token to be processed by
|
||||
+ * the fake CFX context. */
|
||||
+static void
|
||||
+write_cfx_header(uint16_t ec, uint8_t *out)
|
||||
+{
|
||||
+ memset(out, 0, 16);
|
||||
+ store_16_be(KG2_TOK_WRAP_MSG, out);
|
||||
+ out[2] = FLAG_WRAP_CONFIDENTIAL;
|
||||
+ out[3] = 0xFF;
|
||||
+ store_16_be(ec, out + 4);
|
||||
+}
|
||||
+
|
||||
/* Unwrap a superficially valid RFC 1964 token with a CFX-only context, with
|
||||
* regular and IOV unwrap. */
|
||||
static void
|
||||
@@ -238,6 +257,134 @@ test_bogus_1964_token(gss_ctx_id_t ctx)
|
||||
free(in.value);
|
||||
}
|
||||
|
||||
+static void
|
||||
+test_cfx_altered_ec(gss_ctx_id_t ctx, krb5_key subkey)
|
||||
+{
|
||||
+ OM_uint32 major, minor;
|
||||
+ uint8_t tokbuf[128], plainbuf[24];
|
||||
+ krb5_data plain;
|
||||
+ krb5_enc_data cipher;
|
||||
+ gss_buffer_desc in, out;
|
||||
+ gss_iov_buffer_desc iov[2];
|
||||
+
|
||||
+ /* Construct a header with a plaintext EC value of 3. */
|
||||
+ write_cfx_header(3, tokbuf);
|
||||
+
|
||||
+ /* Encrypt a plaintext and a copy of the header with the EC value 0. */
|
||||
+ memcpy(plainbuf, "truncate", 8);
|
||||
+ memcpy(plainbuf + 8, tokbuf, 16);
|
||||
+ store_16_be(0, plainbuf + 12);
|
||||
+ plain = make_data(plainbuf, 24);
|
||||
+ cipher.ciphertext.data = (char *)tokbuf + 16;
|
||||
+ cipher.ciphertext.length = sizeof(tokbuf) - 16;
|
||||
+ cipher.enctype = subkey->keyblock.enctype;
|
||||
+ if (krb5_k_encrypt(NULL, subkey, KG_USAGE_INITIATOR_SEAL, NULL,
|
||||
+ &plain, &cipher) != 0)
|
||||
+ abort();
|
||||
+
|
||||
+ /* Verify that the token is rejected by gss_unwrap(). */
|
||||
+ in.value = tokbuf;
|
||||
+ in.length = 16 + cipher.ciphertext.length;
|
||||
+ major = gss_unwrap(&minor, ctx, &in, &out, NULL, NULL);
|
||||
+ if (major != GSS_S_DEFECTIVE_TOKEN)
|
||||
+ abort();
|
||||
+ (void)gss_release_buffer(&minor, &out);
|
||||
+
|
||||
+ /* Verify that the token is rejected by gss_unwrap_iov(). */
|
||||
+ iov[0].type = GSS_IOV_BUFFER_TYPE_STREAM;
|
||||
+ iov[0].buffer = in;
|
||||
+ iov[1].type = GSS_IOV_BUFFER_TYPE_DATA;
|
||||
+ major = gss_unwrap_iov(&minor, ctx, NULL, NULL, iov, 2);
|
||||
+ if (major != GSS_S_DEFECTIVE_TOKEN)
|
||||
+ abort();
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+test_cfx_short_plaintext(gss_ctx_id_t ctx, krb5_key subkey)
|
||||
+{
|
||||
+ OM_uint32 major, minor;
|
||||
+ uint8_t tokbuf[128], zerobyte = 0;
|
||||
+ krb5_data plain;
|
||||
+ krb5_enc_data cipher;
|
||||
+ gss_buffer_desc in, out;
|
||||
+
|
||||
+ write_cfx_header(0, tokbuf);
|
||||
+
|
||||
+ /* Encrypt a single byte, with no copy of the header. */
|
||||
+ plain = make_data(&zerobyte, 1);
|
||||
+ cipher.ciphertext.data = (char *)tokbuf + 16;
|
||||
+ cipher.ciphertext.length = sizeof(tokbuf) - 16;
|
||||
+ cipher.enctype = subkey->keyblock.enctype;
|
||||
+ if (krb5_k_encrypt(NULL, subkey, KG_USAGE_INITIATOR_SEAL, NULL,
|
||||
+ &plain, &cipher) != 0)
|
||||
+ abort();
|
||||
+
|
||||
+ /* Verify that the token is rejected by gss_unwrap(). */
|
||||
+ in.value = tokbuf;
|
||||
+ in.length = 16 + cipher.ciphertext.length;
|
||||
+ major = gss_unwrap(&minor, ctx, &in, &out, NULL, NULL);
|
||||
+ if (major != GSS_S_DEFECTIVE_TOKEN)
|
||||
+ abort();
|
||||
+ (void)gss_release_buffer(&minor, &out);
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+test_cfx_large_ec(gss_ctx_id_t ctx, krb5_key subkey)
|
||||
+{
|
||||
+ OM_uint32 major, minor;
|
||||
+ uint8_t tokbuf[128] = { 0 }, plainbuf[20];
|
||||
+ krb5_data plain;
|
||||
+ krb5_enc_data cipher;
|
||||
+ gss_buffer_desc in, out;
|
||||
+
|
||||
+ /* Construct a header with an EC value of 5. */
|
||||
+ write_cfx_header(5, tokbuf);
|
||||
+
|
||||
+ /* Encrypt a 4-byte plaintext plus the header. */
|
||||
+ memcpy(plainbuf, "abcd", 4);
|
||||
+ memcpy(plainbuf + 4, tokbuf, 16);
|
||||
+ plain = make_data(plainbuf, 20);
|
||||
+ cipher.ciphertext.data = (char *)tokbuf + 16;
|
||||
+ cipher.ciphertext.length = sizeof(tokbuf) - 16;
|
||||
+ cipher.enctype = subkey->keyblock.enctype;
|
||||
+ if (krb5_k_encrypt(NULL, subkey, KG_USAGE_INITIATOR_SEAL, NULL,
|
||||
+ &plain, &cipher) != 0)
|
||||
+ abort();
|
||||
+
|
||||
+ /* Verify that the token is rejected by gss_unwrap(). */
|
||||
+ in.value = tokbuf;
|
||||
+ in.length = 16 + cipher.ciphertext.length;
|
||||
+ major = gss_unwrap(&minor, ctx, &in, &out, NULL, NULL);
|
||||
+ if (major != GSS_S_DEFECTIVE_TOKEN)
|
||||
+ abort();
|
||||
+ (void)gss_release_buffer(&minor, &out);
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+test_iov_large_asn1_wrapper(gss_ctx_id_t ctx)
|
||||
+{
|
||||
+ OM_uint32 minor, major;
|
||||
+ uint8_t databuf[10] = { 0 };
|
||||
+ gss_iov_buffer_desc iov[2];
|
||||
+
|
||||
+ /*
|
||||
+ * In this IOV array, the header contains a DER tag with a dangling eight
|
||||
+ * bytes of length field. The data IOV indicates a total token length
|
||||
+ * sufficient to contain the length bytes.
|
||||
+ */
|
||||
+ iov[0].type = GSS_IOV_BUFFER_TYPE_HEADER;
|
||||
+ iov[0].buffer.value = ealloc(2);
|
||||
+ iov[0].buffer.length = 2;
|
||||
+ memcpy(iov[0].buffer.value, "\x60\x88", 2);
|
||||
+ iov[1].type = GSS_IOV_BUFFER_TYPE_DATA;
|
||||
+ iov[1].buffer.value = databuf;
|
||||
+ iov[1].buffer.length = 10;
|
||||
+ major = gss_unwrap_iov(&minor, ctx, NULL, NULL, iov, 2);
|
||||
+ if (major != GSS_S_DEFECTIVE_TOKEN)
|
||||
+ abort();
|
||||
+ free(iov[0].buffer.value);
|
||||
+}
|
||||
+
|
||||
/* Process wrap and MIC tokens with incomplete headers. */
|
||||
static void
|
||||
test_short_header(gss_ctx_id_t ctx)
|
||||
@@ -387,9 +534,7 @@ try_accept(void *value, size_t len)
|
||||
gss_ctx_id_t ctx = GSS_C_NO_CONTEXT;
|
||||
|
||||
/* Copy the provided value to make input overruns more obvious. */
|
||||
- in.value = malloc(len);
|
||||
- if (in.value == NULL)
|
||||
- abort();
|
||||
+ in.value = ealloc(len);
|
||||
memcpy(in.value, value, len);
|
||||
in.length = len;
|
||||
(void)gss_accept_sec_context(&minor, &ctx, GSS_C_NO_CREDENTIAL, &in,
|
||||
@@ -424,11 +569,23 @@ test_short_encapsulation()
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
+ krb5_keyblock kb;
|
||||
+ krb5_key cfx_subkey;
|
||||
gss_ctx_id_t ctx;
|
||||
size_t i;
|
||||
|
||||
- ctx = make_fake_cfx_context();
|
||||
+ kb.enctype = ENCTYPE_AES128_CTS_HMAC_SHA1_96;
|
||||
+ kb.length = 16;
|
||||
+ kb.contents = (unsigned char *)"1234567887654321";
|
||||
+ if (krb5_k_create_key(NULL, &kb, &cfx_subkey) != 0)
|
||||
+ abort();
|
||||
+
|
||||
+ ctx = make_fake_cfx_context(cfx_subkey);
|
||||
test_bogus_1964_token(ctx);
|
||||
+ test_cfx_altered_ec(ctx, cfx_subkey);
|
||||
+ test_cfx_short_plaintext(ctx, cfx_subkey);
|
||||
+ test_cfx_large_ec(ctx, cfx_subkey);
|
||||
+ test_iov_large_asn1_wrapper(ctx);
|
||||
free_fake_context(ctx);
|
||||
|
||||
for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) {
|
||||
--
|
||||
2.33.0
|
||||
|
@ -23,6 +23,7 @@ import subprocess
|
||||
#--------------------------------------------------------#
|
||||
|
||||
source_code_path = "kerberos"
|
||||
openssl_path = os.getcwd() + "/../../output/kernel/dependency/openssl/%s/%s"
|
||||
|
||||
class OPOperator():
|
||||
def __init__(self, mode, filename, compiletype):
|
||||
@ -137,8 +138,10 @@ class OPOperator():
|
||||
prepare_cmd = 'mkdir -p %s/install/comm' % (self.local_dir)
|
||||
ret = self.exe_cmd(prepare_cmd)
|
||||
self.error_handler(ret)
|
||||
config_cmd = "cd %s/%s/src; ./configure --prefix=%s/install/comm LDFLAGS='-Wl,-z,relro,-z,now' CFLAGS='-fstack-protector-strong -fPIC' --disable-rpath --disable-pkinit --with-system-verto=no" % (self.local_dir, source_code_path, self.local_dir)
|
||||
print("cd %s/%s/src; ./configure --prefix=%s/install/comm LDFLAGS='-Wl,-z,relro,-z,now' CFLAGS='-fstack-protector-strong -fPIC' --disable-rpath --disable-pkinit --with-system-verto=no" % (self.local_dir, source_code_path, self.local_dir))
|
||||
openssl_comm_lib = (openssl_path % ("comm", "lib"))
|
||||
openssl_comm_include = (openssl_path % ("comm", "include"))
|
||||
config_cmd = "cd %s/%s/src; ./configure --prefix=%s/install/comm LDFLAGS='-Wl,-z,relro,-z,now -L%s' CFLAGS='-fstack-protector-strong -fPIC -I%s' --disable-rpath --disable-pkinit --with-system-verto=no" % (self.local_dir, source_code_path, self.local_dir, openssl_comm_lib, openssl_comm_include)
|
||||
print(config_cmd)
|
||||
ret = self.exe_cmd(config_cmd)
|
||||
self.error_handler(ret)
|
||||
make_cmd = 'cd %s/%s/src; make -j%s && make install' % (self.local_dir, source_code_path, cpu_num)
|
||||
@ -148,8 +151,10 @@ class OPOperator():
|
||||
prepare_cmd = 'mkdir -p %s/install/llt' % (self.local_dir)
|
||||
ret = self.exe_cmd(prepare_cmd)
|
||||
self.error_handler(ret)
|
||||
config_cmd = "cd %s/%s/src; ./configure --prefix=%s/install/llt LDFLAGS='-Wl,-z,relro,-z,now' CFLAGS='-fstack-protector-strong -fPIC' --disable-rpath --disable-pkinit --with-system-verto=no" % (self.local_dir, source_code_path, self.local_dir)
|
||||
print("cd %s/%s/src; ./configure --prefix=%s/install/llt LDFLAGS='-Wl,-z,relro,-z,now' CFLAGS='-fstack-protector-strong -fPIC' --disable-rpath --disable-pkinit --with-system-verto=no" % (self.local_dir, source_code_path, self.local_dir))
|
||||
openssl_llt_lib = (openssl_path % ("llt", "lib"))
|
||||
openssl_llt_include = (openssl_path % ("llt", "include"))
|
||||
config_cmd = "cd %s/%s/src; ./configure --prefix=%s/install/llt LDFLAGS='-Wl,-z,relro,-z,now -L%s' CFLAGS='-fstack-protector-strong -fPIC -I%s' --disable-rpath --disable-pkinit --with-system-verto=no" % (self.local_dir, source_code_path, self.local_dir, openssl_llt_lib, openssl_llt_include)
|
||||
print(config_cmd)
|
||||
ret = self.exe_cmd(config_cmd)
|
||||
self.error_handler(ret)
|
||||
make_cmd = 'cd %s/%s/src; make -j%s && make install' % (self.local_dir, source_code_path, cpu_num)
|
||||
|
70
dependency/libcurl/CVE-2024-2398.patch
Normal file
70
dependency/libcurl/CVE-2024-2398.patch
Normal file
@ -0,0 +1,70 @@
|
||||
diff -Naur a/lib/http2.c b/lib/http2.c
|
||||
--- a/lib/http2.c 2024-04-13 14:42:27.209977032 +0800
|
||||
+++ b/lib/http2.c 2024-04-13 14:33:11.606622746 +0800
|
||||
@@ -547,6 +547,15 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static void free_push_headers(struct h2_stream_ctx *stream)
|
||||
+{
|
||||
+ size_t i;
|
||||
+ for(i = 0; i<stream->push_headers_used; i++)
|
||||
+ free(stream->push_headers[i]);
|
||||
+ Curl_safefree(stream->push_headers);
|
||||
+ stream->push_headers_used = 0;
|
||||
+}
|
||||
+
|
||||
static int push_promise(struct Curl_easy *data,
|
||||
struct connectdata *conn,
|
||||
const nghttp2_push_promise *frame)
|
||||
@@ -560,7 +569,6 @@
|
||||
struct curl_pushheaders heads;
|
||||
CURLMcode rc;
|
||||
struct http_conn *httpc;
|
||||
- size_t i;
|
||||
/* clone the parent */
|
||||
struct Curl_easy *newhandle = duphandle(data);
|
||||
if(!newhandle) {
|
||||
@@ -596,11 +604,7 @@
|
||||
Curl_set_in_callback(data, false);
|
||||
|
||||
/* free the headers again */
|
||||
- for(i = 0; i<stream->push_headers_used; i++)
|
||||
- free(stream->push_headers[i]);
|
||||
- free(stream->push_headers);
|
||||
- stream->push_headers = NULL;
|
||||
- stream->push_headers_used = 0;
|
||||
+ free_push_headers(stream);
|
||||
|
||||
if(rv) {
|
||||
DEBUGASSERT((rv > CURL_PUSH_OK) && (rv <= CURL_PUSH_ERROROUT));
|
||||
@@ -1036,10 +1040,9 @@
|
||||
stream->push_headers_alloc) {
|
||||
char **headp;
|
||||
stream->push_headers_alloc *= 2;
|
||||
- headp = Curl_saferealloc(stream->push_headers,
|
||||
- stream->push_headers_alloc * sizeof(char *));
|
||||
+ headp = realloc(stream->push_headers, stream->push_headers_alloc * sizeof(char *));
|
||||
if(!headp) {
|
||||
- stream->push_headers = NULL;
|
||||
+ free_push_headers(stream);
|
||||
return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
|
||||
}
|
||||
stream->push_headers = headp;
|
||||
@@ -1205,15 +1208,8 @@
|
||||
setup */
|
||||
Curl_dyn_free(&http->header_recvbuf);
|
||||
Curl_dyn_free(&http->trailer_recvbuf);
|
||||
- if(http->push_headers) {
|
||||
- /* if they weren't used and then freed before */
|
||||
- for(; http->push_headers_used > 0; --http->push_headers_used) {
|
||||
- free(http->push_headers[http->push_headers_used - 1]);
|
||||
- }
|
||||
- free(http->push_headers);
|
||||
- http->push_headers = NULL;
|
||||
- }
|
||||
|
||||
+ free_push_headers(http);
|
||||
if(!(data->conn->handler->protocol&PROTO_FAMILY_HTTP) ||
|
||||
!httpc->h2) /* not HTTP/2 ? */
|
||||
return;
|
@ -123,6 +123,7 @@ main()
|
||||
patch -p1 < ../CVE-2023-28322.patch >> $LOG_FILE 2>&1
|
||||
patch -p1 < ../CVE-2023-46218.patch >> $LOG_FILE 2>&1
|
||||
patch -p1 < ../CVE-2023-38545.patch >> $LOG_FILE 2>&1
|
||||
patch -p1 < ../CVE-2024-2398.patch >> $LOG_FILE 2>&1
|
||||
|
||||
checkret "Failed to patch huawei_curl.patch"
|
||||
print_done
|
||||
|
12
dependency/libxml2/CVE-2024-34459.patch
Normal file
12
dependency/libxml2/CVE-2024-34459.patch
Normal file
@ -0,0 +1,12 @@
|
||||
diff -Naur a/xmllint.c b/xmllint.c
|
||||
--- a/xmllint.c 2024-08-05 15:16:19.271124192 +0800
|
||||
+++ b/xmllint.c 2024-08-05 15:20:00.325968893 +0800
|
||||
@@ -602,7 +602,7 @@
|
||||
len = strlen(buffer);
|
||||
snprintf(&buffer[len], sizeof(buffer) - len, "\n");
|
||||
cur = input->cur;
|
||||
- while ((*cur == '\n') || (*cur == '\r'))
|
||||
+ while ((cur > base) && ((*cur == '\n') || (*cur == '\r')))
|
||||
cur--;
|
||||
n = 0;
|
||||
while ((cur != base) && (n++ < 80)) {
|
@ -28,10 +28,11 @@ function build_component()
|
||||
patch -p1 < ../libxml2.patch
|
||||
patch -p1 < ../libxml2-CVE-2022-40303.patch
|
||||
patch -p1 < ../libxml2-CVE-2022-40304.patch
|
||||
patch -p1 < ../CVE-2024-25062.patch
|
||||
patch -p1 < ../CVE-2023-28484.patch
|
||||
patch -p1 < ../CVE-2023-29469.patch
|
||||
patch -p1 < ../CVE-2023-45322.patch
|
||||
patch -p1 < ../CVE-2024-25062.patch
|
||||
patch -p1 < ../CVE-2024-34459.patch
|
||||
tmp_cpus=$(grep -w processor /proc/cpuinfo|wc -l)
|
||||
./autogen.sh
|
||||
chmod +x configure
|
||||
|
116
dependency/llvm/CVE-2024-31852.patch
Normal file
116
dependency/llvm/CVE-2024-31852.patch
Normal file
@ -0,0 +1,116 @@
|
||||
diff -Naur a/llvm/lib/Target/ARM/ARMFrameLowering.cpp b/llvm/lib/Target/ARM/ARMFrameLowering.cpp
|
||||
--- a/llvm/lib/Target/ARM/ARMFrameLowering.cpp 2024-04-15 20:53:13.643344012 +0800
|
||||
+++ b/llvm/lib/Target/ARM/ARMFrameLowering.cpp 2024-04-15 21:13:51.463632273 +0800
|
||||
@@ -1097,9 +1097,6 @@
|
||||
// Fold the return instruction into the LDM.
|
||||
DeleteRet = true;
|
||||
LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_RET : ARM::LDMIA_RET;
|
||||
- // We 'restore' LR into PC so it is not live out of the return block:
|
||||
- // Clear Restored bit.
|
||||
- Info.setRestored(false);
|
||||
} else
|
||||
LdmOpc = AFI->isThumbFunction() ? ARM::t2LDMIA_UPD : ARM::LDMIA_UPD;
|
||||
}
|
||||
@@ -2155,6 +2152,35 @@
|
||||
AFI->setLRIsSpilled(SavedRegs.test(ARM::LR));
|
||||
}
|
||||
|
||||
+void ARMFrameLowering::updateLRRestored(MachineFunction &MF) {
|
||||
+ MachineFrameInfo &MFI = MF.getFrameInfo();
|
||||
+ if (!MFI.isCalleeSavedInfoValid())
|
||||
+ return;
|
||||
+ // Check if all terminators do not implicitly use LR. Then we can 'restore' LR
|
||||
+ // into PC so it is not live out of the return block: Clear the Restored bit
|
||||
+ // in that case.
|
||||
+ for (CalleeSavedInfo &Info : MFI.getCalleeSavedInfo()) {
|
||||
+ if (Info.getReg() != ARM::LR)
|
||||
+ continue;
|
||||
+ if (all_of(MF, [](const MachineBasicBlock &MBB) {
|
||||
+ return all_of(MBB.terminators(), [](const MachineInstr &Term) {
|
||||
+ return !Term.isReturn() || Term.getOpcode() == ARM::LDMIA_RET ||
|
||||
+ Term.getOpcode() == ARM::t2LDMIA_RET ||
|
||||
+ Term.getOpcode() == ARM::tPOP_RET;
|
||||
+ });
|
||||
+ })) {
|
||||
+ Info.setRestored(false);
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void ARMFrameLowering::processFunctionBeforeFrameFinalized(
|
||||
+ MachineFunction &MF, RegScavenger *RS) const {
|
||||
+ TargetFrameLowering::processFunctionBeforeFrameFinalized(MF, RS);
|
||||
+ updateLRRestored(MF);
|
||||
+}
|
||||
+
|
||||
void ARMFrameLowering::getCalleeSaves(const MachineFunction &MF,
|
||||
BitVector &SavedRegs) const {
|
||||
TargetFrameLowering::getCalleeSaves(MF, SavedRegs);
|
||||
diff -Naur a/llvm/lib/Target/ARM/ARMFrameLowering.h b/llvm/lib/Target/ARM/ARMFrameLowering.h
|
||||
--- a/llvm/lib/Target/ARM/ARMFrameLowering.h 2024-04-15 20:53:13.643344012 +0800
|
||||
+++ b/llvm/lib/Target/ARM/ARMFrameLowering.h 2024-04-15 21:13:51.463632273 +0800
|
||||
@@ -58,6 +58,13 @@
|
||||
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
|
||||
RegScavenger *RS) const override;
|
||||
|
||||
+ /// Update the IsRestored flag on LR if it is spilled, based on the return
|
||||
+ /// instructions.
|
||||
+ static void updateLRRestored(MachineFunction &MF);
|
||||
+
|
||||
+ void processFunctionBeforeFrameFinalized(
|
||||
+ MachineFunction &MF, RegScavenger *RS = nullptr) const override;
|
||||
+
|
||||
void adjustForSegmentedStacks(MachineFunction &MF,
|
||||
MachineBasicBlock &MBB) const override;
|
||||
|
||||
diff -Naur a/llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp b/llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp
|
||||
--- a/llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp 2024-04-15 20:53:13.643344012 +0800
|
||||
+++ b/llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp 2024-04-15 21:13:51.483632535 +0800
|
||||
@@ -2037,19 +2037,6 @@
|
||||
MO.setReg(ARM::PC);
|
||||
PrevMI.copyImplicitOps(*MBB.getParent(), *MBBI);
|
||||
MBB.erase(MBBI);
|
||||
- // We now restore LR into PC so it is not live-out of the return block
|
||||
- // anymore: Clear the CSI Restored bit.
|
||||
- MachineFrameInfo &MFI = MBB.getParent()->getFrameInfo();
|
||||
- // CSI should be fixed after PrologEpilog Insertion
|
||||
- assert(MFI.isCalleeSavedInfoValid() && "CSI should be valid");
|
||||
- for (CalleeSavedInfo &Info : MFI.getCalleeSavedInfo()) {
|
||||
- if (Info.getReg() == ARM::LR) {
|
||||
- Info.setRestored(false);
|
||||
- break;
|
||||
- }
|
||||
- }
|
||||
- return true;
|
||||
- }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2095,16 +2082,24 @@
|
||||
isThumb2 = AFI->isThumb2Function();
|
||||
isThumb1 = AFI->isThumbFunction() && !isThumb2;
|
||||
|
||||
- bool Modified = false;
|
||||
+ bool Modified = false, ModifiedLDMReturn = false;
|
||||
for (MachineFunction::iterator MFI = Fn.begin(), E = Fn.end(); MFI != E;
|
||||
++MFI) {
|
||||
MachineBasicBlock &MBB = *MFI;
|
||||
Modified |= LoadStoreMultipleOpti(MBB);
|
||||
if (STI->hasV5TOps())
|
||||
- Modified |= MergeReturnIntoLDM(MBB);
|
||||
+ ModifiedLDMReturn |= MergeReturnIntoLDM(MBB);
|
||||
if (isThumb1)
|
||||
Modified |= CombineMovBx(MBB);
|
||||
}
|
||||
+ Modified |= ModifiedLDMReturn;
|
||||
+
|
||||
+ // If we merged a BX instruction into an LDM, we need to re-calculate whether
|
||||
+ // LR is restored. This check needs to consider the whole function, not just
|
||||
+ // the instruction(s) we changed, because there may be other BX returns which
|
||||
+ // still need LR to be restored.
|
||||
+ if (ModifiedLDMReturn)
|
||||
+ ARMFrameLowering::updateLRRestored(Fn);
|
||||
|
||||
Allocator.DestroyAll();
|
||||
return Modified;
|
@ -23,6 +23,7 @@ function build_llvm()
|
||||
mkdir ${SOURCE_CODE_PATH}
|
||||
tar -zxf $TAR_FILE_NAME -C $SOURCE_CODE_PATH --strip-components 1
|
||||
cd ${LOCAL_DIR}/${SOURCE_CODE_PATH}
|
||||
patch -p1 < ../CVE-2024-31852.patch
|
||||
# patch -p1 < ../0001-llvm.patch
|
||||
# patch -p1 < ../0002-llvm.patch
|
||||
# patch -p1 < ../0003-llvm.patch
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,955 +0,0 @@
|
||||
From 0a2c88b6297fda231a5ca0f922bf732a8d0445dd Mon Sep 17 00:00:00 2001
|
||||
From: Vinoth Veeraraghavan <vinoth.veeraraghavan@hotmail.com>
|
||||
Date: Wed, 23 Mar 2022 19:09:26 +0700
|
||||
Subject: [PATCH] Masstree OOM feature + bug fixes
|
||||
|
||||
More detail: 1. Feature: Add support for memory allocation failure
|
||||
2. Bug fix: RCU\GC: delete node before disconnect
|
||||
3. Bug fix: Leafs are marked as root by mistake
|
||||
4. Bug fix: GC layer might access already freed node
|
||||
5. Bug fix: Memory leak (Layers are not being removed)
|
||||
6. Optimization: Disable some debug\unused code (collect new nodes)
|
||||
7. Optimization: Disable phantom epoch support (not in use by MOT)
|
||||
8. Optimization: Extend node version to 64bit
|
||||
9. Optimization: Optimize leaf size to support larger internal ksuffix
|
||||
---
|
||||
kvthread.hh | 96 ++++++++++++++++++++++++++++++++-----
|
||||
masstree.hh | 5 +-
|
||||
masstree_insert.hh | 78 +++++++++++++++++++++++++++----
|
||||
masstree_remove.hh | 17 +++++--
|
||||
masstree_scan.hh | 4 +-
|
||||
masstree_split.hh | 122 +++++++++++++++++++++++++++++++++++++++++++-----
|
||||
masstree_struct.hh | 72 +++++++++++++++++++++-------
|
||||
masstree_tcursor.hh | 31 ++++++------
|
||||
mot_masstree_config.hpp | 11 ++++-
|
||||
9 files changed, 365 insertions(+), 71 deletions(-)
|
||||
|
||||
diff --git a/kvthread.hh b/kvthread.hh
|
||||
index 2c75e4e..364cd44 100644
|
||||
--- a/kvthread.hh
|
||||
+++ b/kvthread.hh
|
||||
@@ -24,6 +24,48 @@
|
||||
#include <pthread.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdlib.h>
|
||||
+#include <vector>
|
||||
+
|
||||
+enum {
|
||||
+ MT_MERR_OK = 0,
|
||||
+ MT_MERR_MAKE_SPLIT_PRE_ALLOC = 1,
|
||||
+ MT_MERR_MAKE_SPLIT_LEAF_ALLOC = 2,
|
||||
+ MT_MERR_MAKE_NEW_LAYER_LEAF_ALLOC_1 = 3,
|
||||
+ MT_MERR_MAKE_NEW_LAYER_LEAF_ALLOC_2 = 4,
|
||||
+ MT_MERR_MAKE_NEW_LAYER_KSUFFIX_ALLOC_1 = 5,
|
||||
+ MT_MERR_MAKE_NEW_LAYER_KSUFFIX_ALLOC_2 = 6,
|
||||
+ MT_MERR_FIND_INSERT_ASSIGN_SUFFIX = 7,
|
||||
+ MT_MERR_SPLIT_INTO_ASSIGN_INITALIZE_1 = 8,
|
||||
+ MT_MERR_SPLIT_INTO_ASSIGN_INITALIZE_2 = 9,
|
||||
+ MT_MERR_GC_LAYER_REMOVAL_MAKE = 10,
|
||||
+ MT_MERR_MAKE_SPLIT_ASSIGN_SUFFIX = 11,
|
||||
+ MT_MERR_MAKE_SPLIT_PERM_EXCHANGE = 12,
|
||||
+
|
||||
+ // Errors that are being handled internally (Operation should succeed even if last error contains them)
|
||||
+ MT_MERR_NON_DISRUPTIVE_ERRORS = 15,
|
||||
+
|
||||
+ // We should not reach the following errors as they should be covered with other errors in more upper layer
|
||||
+ MT_MERR_NOT_RETURNED_TO_USER_ERRORS = 20,
|
||||
+ MT_MERR_ASSIGN_KSUF = 21,
|
||||
+ MT_MERR_MAKE_LEAF = 22,
|
||||
+ MT_MERR_MAKE_ROOT_LEAF = 23,
|
||||
+ MT_MERR_MAKE_INTERNODE = 24,
|
||||
+ MT_MERR_LEAF_ASSIGN = 25,
|
||||
+ MT_MERR_ASSIGN_INITALIZE_1 = 26,
|
||||
+ MT_MERR_ASSIGN_INITALIZE_2 = 27,
|
||||
+
|
||||
+ // We should not reach the following errors
|
||||
+ MT_MERR_UNREACHABLE_ERRORS = 30,
|
||||
+ MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_NOT_EXPECTED,
|
||||
+ MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_NOT_EXPECTED_2,
|
||||
+ MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_EMPTY_PRE_ALLOC_NOT_EXPECTED,
|
||||
+ MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_EMPTY_PRE_ALLOC_NOT_EXPECTED_2,
|
||||
+
|
||||
+ MT_MERR_NOT_IN_USE_LAST_ENTRY = 40
|
||||
+};
|
||||
+
|
||||
+#define MAX_ALLOC_ERROR_TYPES MT_MERR_NOT_IN_USE_LAST_ENTRY
|
||||
+
|
||||
|
||||
class threadinfo;
|
||||
class loginfo;
|
||||
@@ -42,7 +84,7 @@ extern volatile mrcu_epoch_type globalepoch; // global epoch, updated regularly
|
||||
extern volatile mrcu_epoch_type active_epoch;
|
||||
|
||||
// Memtags max allocation size
|
||||
-#define MAX_MEMTAG_MASSTREE_LEAF_ALLOCATION_SIZE iceil(sizeof(leaf<P>) + 128, 64)
|
||||
+#define MAX_MEMTAG_MASSTREE_LEAF_ALLOCATION_SIZE iceil(sizeof(leaf<P>) + 128, 64)
|
||||
#define MAX_MEMTAG_MASSTREE_INTERNODE_ALLOCATION_SIZE sizeof(internode<P>)
|
||||
#define MAX_MEMTAG_MASSTREE_LIMBO_GROUP_ALLOCATION_SIZE sizeof(mt_limbo_group)
|
||||
|
||||
@@ -117,6 +159,12 @@ class alignas(64) threadinfo {
|
||||
TI_MAIN, TI_PROCESS, TI_LOG, TI_CHECKPOINT
|
||||
};
|
||||
|
||||
+ typedef struct rcu_entry {
|
||||
+ void* p;
|
||||
+ size_t sz;
|
||||
+ memtag tag;
|
||||
+ } rcu_entry_t;
|
||||
+
|
||||
static threadinfo* allthreads;
|
||||
|
||||
threadinfo* next() const {
|
||||
@@ -229,15 +277,14 @@ class alignas(64) threadinfo {
|
||||
|
||||
void deallocate_rcu(void* p, size_t sz, memtag tag) {
|
||||
assert(p);
|
||||
- memdebug::check_rcu(p, sz, tag);
|
||||
- record_rcu(p, sz, tag);
|
||||
- mark(threadcounter(tc_alloc + (tag > memtag_value)), -sz);
|
||||
+ dealloc_rcu.push_back({p, sz, tag});
|
||||
}
|
||||
|
||||
void* pool_allocate(size_t sz, memtag tag) {
|
||||
void* p = NULL;
|
||||
int nl = (sz + memdebug_size + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE;
|
||||
if (use_pool()) {
|
||||
+ masstree_invariant(false); // mot code should not reach here
|
||||
assert(nl <= pool_max_nlines);
|
||||
if (unlikely(!pool_[nl - 1]))
|
||||
refill_pool(nl);
|
||||
@@ -264,17 +311,30 @@ class alignas(64) threadinfo {
|
||||
*reinterpret_cast<void **>(p) = pool_[nl - 1];
|
||||
pool_[nl - 1] = p;
|
||||
} else
|
||||
- free(p);
|
||||
+ deallocate(p, sz, tag); // mot memory deallocation
|
||||
mark(threadcounter(tc_alloc + (tag > memtag_value)),
|
||||
-nl * CACHE_LINE_SIZE);
|
||||
}
|
||||
void pool_deallocate_rcu(void* p, size_t sz, memtag tag) {
|
||||
- int nl = (sz + memdebug_size + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE;
|
||||
- assert(p && nl <= pool_max_nlines);
|
||||
- memdebug::check_rcu(p, sz, memtag(tag + nl));
|
||||
- record_rcu(p, sz, use_pool() ? memtag(tag + nl) : tag);
|
||||
- mark(threadcounter(tc_alloc + (tag > memtag_value)),
|
||||
- -nl * CACHE_LINE_SIZE);
|
||||
+ if (unlikely(use_pool())) {
|
||||
+ int nl = (sz + memdebug_size + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE;
|
||||
+ assert(p && nl <= pool_max_nlines);
|
||||
+ memdebug::check_rcu(p, sz, memtag(tag + nl));
|
||||
+ mark(threadcounter(tc_alloc + (tag > memtag_value)),
|
||||
+ -nl * CACHE_LINE_SIZE);
|
||||
+ dealloc_rcu.push_back({p, sz, memtag(tag + nl)});
|
||||
+ } else {
|
||||
+ dealloc_rcu.push_back({p, sz, tag});
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ void add_nodes_to_gc() {
|
||||
+ for (uint32_t i = 0 ; i < dealloc_rcu.size() ; i++) {
|
||||
+ masstree_invariant(dealloc_rcu[i].p);
|
||||
+ record_rcu(dealloc_rcu[i].p, dealloc_rcu[i].sz, dealloc_rcu[i].tag);
|
||||
+ dealloc_rcu[i].p = nullptr;
|
||||
+ }
|
||||
+ dealloc_rcu.clear();
|
||||
}
|
||||
|
||||
// RCU
|
||||
@@ -308,6 +368,11 @@ class alignas(64) threadinfo {
|
||||
return pthreadid_;
|
||||
}
|
||||
|
||||
+ inline void set_last_error(int error) { masstree_invariant(error < MT_MERR_UNREACHABLE_ERRORS); last_error = error; }
|
||||
+ inline int get_last_error() { return last_error; }
|
||||
+ inline bool non_disruptive_error() { return last_error == 0 ||
|
||||
+ (last_error > MT_MERR_NON_DISRUPTIVE_ERRORS && last_error < MT_MERR_NOT_RETURNED_TO_USER_ERRORS); }
|
||||
+
|
||||
void report_rcu(void* ptr) const;
|
||||
static void report_rcu_all(void* ptr);
|
||||
static inline mrcu_epoch_type min_active_epoch();
|
||||
@@ -333,8 +398,14 @@ class alignas(64) threadinfo {
|
||||
#endif
|
||||
}
|
||||
|
||||
+ bool is_empty_rcu_array() {
|
||||
+ return dealloc_rcu.size() == 0;
|
||||
+ }
|
||||
+
|
||||
private:
|
||||
MOT::MasstreePrimaryIndex * cur_working_index;
|
||||
+ int last_error = MT_MERR_OK;
|
||||
+ std::vector<struct rcu_entry> dealloc_rcu;
|
||||
union {
|
||||
struct {
|
||||
mrcu_epoch_type gc_epoch_;
|
||||
@@ -386,7 +457,8 @@ class alignas(64) threadinfo {
|
||||
void ng_record_rcu(void* ptr, int size, memtag tag);
|
||||
|
||||
void record_rcu(void* ptr, int size, memtag tag) {
|
||||
- if (use_pool()) {
|
||||
+ if (unlikely(use_pool())) {
|
||||
+ masstree_invariant(false); // mot code should not reach here
|
||||
if (limbo_tail_->tail_ + 2 > limbo_tail_->capacity)
|
||||
refill_rcu();
|
||||
uint64_t epoch = ng_getGlobalEpoch();
|
||||
diff --git a/masstree.hh b/masstree.hh
|
||||
index eaf6503..89af0ee 100644
|
||||
--- a/masstree.hh
|
||||
+++ b/masstree.hh
|
||||
@@ -42,8 +42,8 @@ template <int LW = 15, int IW = LW> struct nodeparams {
|
||||
static constexpr int bound_method = bound_method_fast;
|
||||
static constexpr int debug_level = 0;
|
||||
typedef uint64_t ikey_type;
|
||||
- typedef uint32_t nodeversion_value_type;
|
||||
- static constexpr bool need_phantom_epoch = true;
|
||||
+ typedef uint64_t nodeversion_value_type;
|
||||
+ static constexpr bool need_phantom_epoch = false;
|
||||
typedef uint64_t phantom_epoch_type;
|
||||
static constexpr ssize_t print_max_indent_depth = 12;
|
||||
typedef key_unparse_printable_string key_unparse_type;
|
||||
@@ -95,6 +95,7 @@ class basic_table {
|
||||
|
||||
inline node_type* root() const;
|
||||
inline node_type* fix_root();
|
||||
+ inline node_type** root_ref() { return &root_; }
|
||||
|
||||
bool get(Str key, value_type& value, threadinfo& ti) const;
|
||||
|
||||
diff --git a/masstree_insert.hh b/masstree_insert.hh
|
||||
index 4a71942..e641f03 100644
|
||||
--- a/masstree_insert.hh
|
||||
+++ b/masstree_insert.hh
|
||||
@@ -21,15 +21,18 @@
|
||||
namespace Masstree {
|
||||
|
||||
template <typename P>
|
||||
-bool tcursor<P>::find_insert(threadinfo& ti)
|
||||
+bool tcursor<P>::find_insert(threadinfo& ti, bool & found)
|
||||
{
|
||||
+ found = false;
|
||||
find_locked(ti);
|
||||
original_n_ = n_;
|
||||
original_v_ = n_->full_unlocked_version_value();
|
||||
|
||||
// maybe we found it
|
||||
- if (state_)
|
||||
+ if (state_) {
|
||||
+ found = true;
|
||||
return true;
|
||||
+ }
|
||||
|
||||
// otherwise mark as inserted but not present
|
||||
state_ = 2;
|
||||
@@ -59,8 +62,11 @@ bool tcursor<P>::find_insert(threadinfo& ti)
|
||||
1. If leaf is the most left leaf in the btree which means ikey0_[0] is not used as a boundary. (!n_->prev_)
|
||||
2. If a new key, with ikey == ikey0_[0], is added. In this case, we can re-use slot 0 as we won't change the tree's structure. (n_->ikey_bound() == ka_.ikey()) */
|
||||
if (likely(kx_.p != 0) || !n_->prev_ || n_->ikey_bound() == ka_.ikey()) {
|
||||
- n_->assign(kx_.p, ka_, ti);
|
||||
- return false;
|
||||
+ // if n_->assign fails, we dont have enough space to place the suffix and we failed while allocating larger ksuffix.
|
||||
+ bool res = n_->assign(kx_.p, ka_, ti);
|
||||
+ if (!res)
|
||||
+ ti.set_last_error(MT_MERR_FIND_INSERT_ASSIGN_SUFFIX);
|
||||
+ return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +84,13 @@ bool tcursor<P>::make_new_layer(threadinfo& ti) {
|
||||
// For each ikey_size bytes (currently 8) that matches in both key's suffixes, we will need to create a new layer
|
||||
leaf_type* twig_head = n_;
|
||||
leaf_type* twig_tail = n_;
|
||||
+ leaf_type* nl = nullptr;
|
||||
while (kcmp == 0) {
|
||||
- leaf_type* nl = leaf_type::make_root(0, twig_tail, ti);
|
||||
+ nl = leaf_type::make_root(0, twig_tail, ti);
|
||||
+ if (!nl) {
|
||||
+ ti.set_last_error(MT_MERR_MAKE_NEW_LAYER_LEAF_ALLOC_1);
|
||||
+ goto make_new_layer_cleanup;
|
||||
+ }
|
||||
nl->assign_initialize_for_layer(0, oka);
|
||||
if (twig_head != n_)
|
||||
twig_tail->lv_[0] = nl;
|
||||
@@ -87,7 +98,9 @@ bool tcursor<P>::make_new_layer(threadinfo& ti) {
|
||||
twig_head = nl;
|
||||
nl->permutation_ = permuter_type::make_sorted(1);
|
||||
twig_tail = nl;
|
||||
+#ifndef MOT_OBSOLETE_CODE
|
||||
new_nodes_.emplace_back(nl, nl->full_unlocked_version_value());
|
||||
+#endif
|
||||
oka.shift();
|
||||
ka_.shift();
|
||||
// Compare the ikey only. if ikey matches and one or more of the suffixes != 0, compare using suffix size
|
||||
@@ -102,9 +115,24 @@ bool tcursor<P>::make_new_layer(threadinfo& ti) {
|
||||
+ n_->iksuf_[0].overhead(n_->width);
|
||||
else
|
||||
ksufsize = 0;
|
||||
- leaf_type *nl = leaf_type::make_root(ksufsize, twig_tail, ti);
|
||||
- nl->assign_initialize(0, kcmp < 0 ? oka : ka_, ti);
|
||||
- nl->assign_initialize(1, kcmp < 0 ? ka_ : oka, ti);
|
||||
+ nl = leaf_type::make_root(ksufsize, twig_tail, ti);
|
||||
+ if (!nl) {
|
||||
+ ti.set_last_error(MT_MERR_MAKE_NEW_LAYER_LEAF_ALLOC_2);
|
||||
+ goto make_new_layer_cleanup;
|
||||
+ }
|
||||
+ // Even though the total ksuffix size was already provided to make_root, more memory might be allocated in assign_initialize calls
|
||||
+ // as leaf internal suffix is bounded by 128 (+ 64 alignment).
|
||||
+ // We will hit this issue (for sure) if ka_.suffix_length() + oka.suffix_length() > 192, but might hit it also when ka_.suffix_length() + oka.suffix_length() > 128.
|
||||
+ if (!nl->assign_initialize(0, kcmp < 0 ? oka : ka_, ti)) {
|
||||
+ ti.set_last_error(MT_MERR_MAKE_NEW_LAYER_KSUFFIX_ALLOC_1);
|
||||
+ goto make_new_layer_cleanup;
|
||||
+ }
|
||||
+
|
||||
+ if (!nl->assign_initialize(1, kcmp < 0 ? ka_ : oka, ti)) {
|
||||
+ ti.set_last_error(MT_MERR_MAKE_NEW_LAYER_KSUFFIX_ALLOC_2);
|
||||
+ goto make_new_layer_cleanup;
|
||||
+ }
|
||||
+
|
||||
nl->lv_[kcmp > 0] = n_->lv_[kx_.p];
|
||||
nl->lock(*nl, ti.lock_fence(tc_leaf_lock));
|
||||
if (kcmp < 0)
|
||||
@@ -134,6 +162,33 @@ bool tcursor<P>::make_new_layer(threadinfo& ti) {
|
||||
n_->unlock();
|
||||
n_ = nl;
|
||||
kx_.i = kx_.p = kcmp < 0;
|
||||
+ return true;
|
||||
+
|
||||
+make_new_layer_cleanup:
|
||||
+ // n_ was not updated yet. It contains the original key (without any change). it will be unlocked later on (in lp.finish)
|
||||
+ if (nl) {
|
||||
+ // nl is not connected yet to twig_tail. handle it seperatly
|
||||
+ nl->deallocate(ti);
|
||||
+ nl = nullptr;
|
||||
+ }
|
||||
+
|
||||
+ // Leafs in leaf list (starts from twig_head) has no suffix. In addition, they are not connected to the masstree yet, so we dont need to hold any locks.
|
||||
+ if (twig_head != n_) {
|
||||
+ while (twig_head) {
|
||||
+ masstree_invariant(!twig_head->ksuf_);
|
||||
+ masstree_invariant(twig_head->size() == 1);
|
||||
+ masstree_invariant(twig_head->is_layer(0));
|
||||
+ masstree_invariant(twig_head->stable_annotated(ti.stable_fence()).is_root());
|
||||
+ leaf_type *next_layer_leaf = (leaf_type *)twig_head->lv_[0].layer();
|
||||
+ twig_head->lv_[0] = nullptr;
|
||||
+ // Remove it directly. no need to use rcu.
|
||||
+ ti.deallocate(twig_head, sizeof(*twig_head) /* Being ignored */, memtag_masstree_leaf);
|
||||
+ // Stop if we just finished to handle last leaf in list (twig_tail).
|
||||
+ // Validating that next_layer_leaf != null wont work as twig_tail->lv_[0] == twig_tail.
|
||||
+ twig_head = (twig_head == twig_tail) ? nullptr : next_layer_leaf;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -152,15 +207,20 @@ inline void tcursor<P>::finish(int state, threadinfo& ti)
|
||||
{
|
||||
if (state < 0 && state_ == 1) {
|
||||
if (finish_remove(ti))
|
||||
- return;
|
||||
+ goto clean_ti;
|
||||
} else if (state > 0 && state_ == 2)
|
||||
finish_insert();
|
||||
// we finally know this!
|
||||
if (n_ == original_n_)
|
||||
updated_v_ = n_->full_unlocked_version_value();
|
||||
+#ifndef MOT_OBSOLETE_CODE
|
||||
else
|
||||
new_nodes_.emplace_back(n_, n_->full_unlocked_version_value());
|
||||
+#endif
|
||||
n_->unlock();
|
||||
+
|
||||
+clean_ti:
|
||||
+ ti.add_nodes_to_gc();
|
||||
}
|
||||
|
||||
} // namespace Masstree
|
||||
diff --git a/masstree_remove.hh b/masstree_remove.hh
|
||||
index 5795261..a647ea5 100644
|
||||
--- a/masstree_remove.hh
|
||||
+++ b/masstree_remove.hh
|
||||
@@ -144,8 +144,9 @@ void gc_layer_rcu_callback<P>::operator()(threadinfo& ti)
|
||||
if (!do_remove || !lp.finish_remove(ti)) {
|
||||
lp.n_->unlock();
|
||||
}
|
||||
- ti.deallocate(this, size(), memtag_masstree_gc);
|
||||
}
|
||||
+ ti.deallocate(this, size(), memtag_masstree_gc);
|
||||
+ ti.add_nodes_to_gc();
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
@@ -172,18 +173,18 @@ bool tcursor<P>::finish_remove(threadinfo& ti) {
|
||||
if (perm.size()) {
|
||||
return false;
|
||||
} else {
|
||||
- return remove_leaf(n_, root_, ka_.prefix_string(), ti);
|
||||
+ return remove_leaf(n_, root_ref_, ka_.prefix_string(), ti);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
-bool tcursor<P>::remove_leaf(leaf_type* leaf, node_type* root,
|
||||
+bool tcursor<P>::remove_leaf(leaf_type* leaf, node_type** root_ref,
|
||||
Str prefix, threadinfo& ti)
|
||||
{
|
||||
if (!leaf->prev_) {
|
||||
if (!leaf->next_.ptr && !prefix.empty()) {
|
||||
// Leaf doesn't hold any keys, not in the highest layer and has no neighbors --> entire layer can be destroyed
|
||||
- gc_layer_rcu_callback_ng<P>::make(root, prefix, ti);
|
||||
+ gc_layer_rcu_callback_ng<P>::make(root_ref, prefix, ti);
|
||||
}
|
||||
// Leaf has neighbor to the right (next) or leaf in the highest layer. do nothing
|
||||
return false;
|
||||
@@ -211,6 +212,14 @@ bool tcursor<P>::remove_leaf(leaf_type* leaf, node_type* root,
|
||||
// Unlink leaf from doubly-linked leaf list
|
||||
btree_leaflink<leaf_type>::unlink(leaf);
|
||||
|
||||
+ // leaf->prev_ != NULL
|
||||
+ leaf_type *prev = leaf->prev_;
|
||||
+ if (!prev->prev_ && !prev->next_.ptr && prev->size() == 0 && !prefix.empty() ) {
|
||||
+ // After removing the leaf, only the most left leaf remains (single leaf). We can remove the layer as the most left leaf
|
||||
+ // doesn't hold any keys and layer is not the highest one.
|
||||
+ gc_layer_rcu_callback_ng<P>::make(root_ref, prefix, ti);
|
||||
+ }
|
||||
+
|
||||
// Remove leaf from tree, collapse trivial chains, and rewrite
|
||||
// ikey bounds.
|
||||
ikey_type ikey = leaf->ikey_bound();
|
||||
diff --git a/masstree_scan.hh b/masstree_scan.hh
|
||||
index 31ffcbc..f7b0937 100644
|
||||
--- a/masstree_scan.hh
|
||||
+++ b/masstree_scan.hh
|
||||
@@ -306,8 +306,10 @@ int scanstackelt<P>::find_next(H &helper, key_type &ka, leafvalue_type &entry)
|
||||
fence();
|
||||
entry = n_->lv_[kp];
|
||||
entry.prefetch(keylenx);
|
||||
- if (n_->keylenx_has_ksuf(keylenx))
|
||||
+ if (n_->keylenx_has_ksuf(keylenx)) {
|
||||
keylen = ka.assign_store_suffix(n_->ksuf(kp));
|
||||
+ masstree_invariant(keylen < (int)MASSTREE_MAXKEYLEN);
|
||||
+ }
|
||||
|
||||
if (n_->has_changed(v_))
|
||||
goto changed;
|
||||
diff --git a/masstree_split.hh b/masstree_split.hh
|
||||
index fcf35ee..42b012b 100644
|
||||
--- a/masstree_split.hh
|
||||
+++ b/masstree_split.hh
|
||||
@@ -46,7 +46,7 @@ leaf<P>::ikey_after_insert(const permuter_type& perm, int i,
|
||||
|
||||
The split type is 0 if @a ka went into *this, 1 if the @a ka went into
|
||||
*@a nr, and 2 for the sequential-order optimization (@a ka went into *@a
|
||||
- nr and no other keys were moved). */
|
||||
+ nr and no other keys were moved). if -1, split failed due to memory issue */
|
||||
template <typename P>
|
||||
int leaf<P>::split_into(leaf<P>* nr, tcursor<P>* cursor,
|
||||
ikey_type& split_ikey, threadinfo& ti)
|
||||
@@ -71,7 +71,8 @@ int leaf<P>::split_into(leaf<P>* nr, tcursor<P>* cursor,
|
||||
int p = cursor->kx_.i;
|
||||
if (p == 0 && !this->prev_) {
|
||||
// reverse-sequential optimization
|
||||
- mid = 1;
|
||||
+ // We remove this optimization as it can lead us to empty leaf (In case insertion fails)
|
||||
+ // mid = 1;
|
||||
} else if (p == width && !this->next_.ptr) {
|
||||
// sequential optimization
|
||||
mid = width;
|
||||
@@ -100,9 +101,16 @@ int leaf<P>::split_into(leaf<P>* nr, tcursor<P>* cursor,
|
||||
typename permuter_type::value_type pv = perml.value_from(mid - (p < mid));
|
||||
for (int x = mid; x <= width; ++x) {
|
||||
if (x == p) {
|
||||
- nr->assign_initialize(x - mid, cursor->ka_, ti);
|
||||
+ if (!nr->assign_initialize(x - mid, cursor->ka_, ti)) {
|
||||
+ ti.set_last_error(MT_MERR_SPLIT_INTO_ASSIGN_INITALIZE_1);
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
} else {
|
||||
- nr->assign_initialize(x - mid, this, pv & 15, ti);
|
||||
+ if (!nr->assign_initialize(x - mid, this, pv & 15, ti)) {
|
||||
+ ti.set_last_error(MT_MERR_SPLIT_INTO_ASSIGN_INITALIZE_2);
|
||||
+ return -1;
|
||||
+ }
|
||||
pv >>= 4;
|
||||
}
|
||||
}
|
||||
@@ -174,6 +182,14 @@ int internode<P>::split_into(internode<P>* nr, int p, ikey_type ka,
|
||||
}
|
||||
}
|
||||
|
||||
+template <typename P>
|
||||
+void tcursor<P>::release_internodes(internode_type * internodes_array[], int start, int end, threadinfo& ti) {
|
||||
+ for (int i = start; i < end; i++) {
|
||||
+ masstree_invariant(internodes_array[i]);
|
||||
+ ti.deallocate(internodes_array[i], sizeof(*internodes_array[i]) /* Being ignored */, memtag_masstree_internode);
|
||||
+ internodes_array[i] = nullptr;
|
||||
+ }
|
||||
+}
|
||||
|
||||
template <typename P>
|
||||
bool tcursor<P>::make_split(threadinfo& ti)
|
||||
@@ -191,17 +207,66 @@ bool tcursor<P>::make_split(threadinfo& ti)
|
||||
if (kx_.p != 0) {
|
||||
n_->permutation_ = perm.value();
|
||||
fence();
|
||||
- n_->assign(kx_.p, ka_, ti);
|
||||
+ if (n_->assign(kx_.p, ka_, ti)) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_PERM_EXCHANGE);
|
||||
+ return false;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ bool rc = true;
|
||||
+
|
||||
+ // 2 optimizations that can reduce the number of internodes allocations:
|
||||
+ // 1. In n_ does not have parent, only 1 internode is required (rare case - only on first split)
|
||||
+ // 2. In case n_'s parent has extra place, and it's height is 1, we dont need internodes at all (common case, but requires early lock of n_'s parent)
|
||||
+ node_type* l_root = n_;
|
||||
+
|
||||
+ while (!l_root->is_root()) {
|
||||
+ if (n_ != l_root) {
|
||||
+ l_root->stable_annotated(ti.stable_fence());
|
||||
+ }
|
||||
+ l_root = l_root->maybe_parent();
|
||||
+ }
|
||||
+
|
||||
+ // l_root->height_ is the layer real height or higher.
|
||||
+ uint32_t layer_height = l_root->isleaf() ? 1 : ((internode_type *)l_root)->height_;
|
||||
+ int reserved_nodes = layer_height + 5; // add 5 extra nodes (extra 5 layers in single b-tree)
|
||||
+ internode_type * preallocated_internodes[reserved_nodes + 1] = { 0 };
|
||||
+ int cur_cache_index = 0;
|
||||
+
|
||||
+ for (int i = 0; i < reserved_nodes; i++) {
|
||||
+ preallocated_internodes[i] = (internode_type *)ti.pool_allocate(MAX_MEMTAG_MASSTREE_INTERNODE_ALLOCATION_SIZE,
|
||||
+ memtag_masstree_internode);
|
||||
+ if (!preallocated_internodes[i]) {
|
||||
+ release_internodes(preallocated_internodes, 0, i, ti);
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_PRE_ALLOC);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
node_type* child = leaf_type::make(n_->ksuf_used_capacity(), n_->phantom_epoch(), ti);
|
||||
+ if (!child) {
|
||||
+ release_internodes(preallocated_internodes, 0, reserved_nodes, ti);
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_LEAF_ALLOC);
|
||||
+ return false;
|
||||
+ }
|
||||
child->assign_version(*n_);
|
||||
+ child->mark_nonroot();
|
||||
+ // As n_ is locked, child is locked as well.
|
||||
ikey_type xikey[2];
|
||||
// Add the new key and spread the keys between the 2 leafs. The new key might be inserted to either one of the leafs. Link to parent will be done later.
|
||||
int split_type = n_->split_into(static_cast<leaf_type*>(child),
|
||||
this, xikey[0], ti);
|
||||
+
|
||||
+ if (split_type < 0) {
|
||||
+ // Split failed due to ksuffix memory allocation error (child is not connected to n_ at this stage)
|
||||
+ release_internodes(preallocated_internodes, 0, reserved_nodes, ti);
|
||||
+ // child is not visiable yet, so we can deallocate without rcu
|
||||
+ ((leaf_type *)child)->deallocate(ti);
|
||||
+ child = nullptr;
|
||||
+ return false;
|
||||
+ }
|
||||
unsigned sense = 0;
|
||||
node_type* n = n_;
|
||||
uint32_t height = 0;
|
||||
@@ -219,7 +284,17 @@ bool tcursor<P>::make_split(threadinfo& ti)
|
||||
}
|
||||
|
||||
if (kp < 0 || p->height_ > height + 1) {
|
||||
- internode_type *nn = internode_type::make(height + 1, ti);
|
||||
+ masstree_invariant(preallocated_internodes[cur_cache_index]);
|
||||
+ internode_type *nn = internode_type::make(height + 1, ti, preallocated_internodes[cur_cache_index++]);
|
||||
+ if (!nn) {
|
||||
+ // Should never happen with pre-allocated internodes. bad flow is not handled
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_NOT_EXPECTED);
|
||||
+ }
|
||||
+
|
||||
+ if (cur_cache_index == reserved_nodes) {
|
||||
+ // Should never happen with pre-allocated internodes (we should have enough reserved nodes). bad flow is not handled
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_EMPTY_PRE_ALLOC_NOT_EXPECTED);
|
||||
+ }
|
||||
nn->child_[0] = n;
|
||||
nn->assign(0, xikey[sense], child);
|
||||
nn->nkeys_ = 1;
|
||||
@@ -233,11 +308,22 @@ bool tcursor<P>::make_split(threadinfo& ti)
|
||||
n->set_parent(nn);
|
||||
} else {
|
||||
if (p->size() >= p->width) {
|
||||
- next_child = internode_type::make(height + 1, ti);
|
||||
+ masstree_invariant(preallocated_internodes[cur_cache_index]);
|
||||
+ next_child = internode_type::make(height + 1, ti, preallocated_internodes[cur_cache_index++]);
|
||||
+ if (!next_child) {
|
||||
+ // Should never happen with pre-allocated internodes. bad flow is not handled
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_NOT_EXPECTED_2);
|
||||
+ }
|
||||
+
|
||||
+ if (cur_cache_index == reserved_nodes) {
|
||||
+ // Should never happen with pre-allocated internodes (we should have enough reserved nodes). bad flow is not handled
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_EMPTY_PRE_ALLOC_NOT_EXPECTED_2);
|
||||
+ }
|
||||
+
|
||||
next_child->assign_version(*p);
|
||||
next_child->mark_nonroot();
|
||||
kp = p->split_into(next_child, kp, xikey[sense],
|
||||
- child, xikey[sense ^ 1], split_type);
|
||||
+ child, xikey[sense ^ 1], split_type); // No memory allocation
|
||||
}
|
||||
if (kp >= 0) {
|
||||
p->shift_up(kp + 1, kp, p->size() - kp);
|
||||
@@ -259,16 +345,27 @@ bool tcursor<P>::make_split(threadinfo& ti)
|
||||
int width = perml.size();
|
||||
perml.set_size(width - nr->size());
|
||||
// removed item, if any, must be @ perml.size()
|
||||
+ int perm_size = perml.size();
|
||||
+ masstree_invariant(perm_size > 0); // Verify that the leaf is not empty
|
||||
if (width != nl->width) {
|
||||
- perml.exchange(perml.size(), nl->width - 1);
|
||||
+ perml.exchange(perm_size, nl->width - 1);
|
||||
}
|
||||
nl->mark_split();
|
||||
nl->permutation_ = perml.value();
|
||||
// account for split
|
||||
if (split_type == 0) {
|
||||
kx_.p = perml.back();
|
||||
- nl->assign(kx_.p, ka_, ti);
|
||||
+
|
||||
+ // In case the new inserted key should be placed in the origianl leaf (left leaf), memory allocation might be needed for it's ksuffix.
|
||||
+ // If assign fails (--> memory allocation failure), the flow will continue, but we mark rc as false to indicate that the insertion failed.
|
||||
+ // In this case, the key wont be exposed in finish_insert(), but the leaf split will be completed successfully.
|
||||
+ if (!nl->assign(kx_.p, ka_, ti)) {
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_ASSIGN_SUFFIX);
|
||||
+ rc = false;
|
||||
+ }
|
||||
+#ifndef MOT_OBSOLETE_CODE
|
||||
new_nodes_.emplace_back(nr, nr->full_unlocked_version_value());
|
||||
+#endif
|
||||
} else {
|
||||
kx_.i = kx_.p = kx_.i - perml.size();
|
||||
n_ = nr;
|
||||
@@ -296,7 +393,10 @@ bool tcursor<P>::make_split(threadinfo& ti)
|
||||
}
|
||||
}
|
||||
|
||||
- return false;
|
||||
+ // Free unused pre-allocated internodes
|
||||
+ release_internodes(preallocated_internodes, cur_cache_index, reserved_nodes, ti);
|
||||
+
|
||||
+ return rc;
|
||||
}
|
||||
|
||||
} // namespace Masstree
|
||||
diff --git a/masstree_struct.hh b/masstree_struct.hh
|
||||
index 8f121a9..1b5d853 100644
|
||||
--- a/masstree_struct.hh
|
||||
+++ b/masstree_struct.hh
|
||||
@@ -120,9 +120,15 @@ class internode : public node_base<P> {
|
||||
: node_base<P>(false), nkeys_(0), height_(height), parent_() {
|
||||
}
|
||||
|
||||
- static internode<P>* make(uint32_t height, threadinfo& ti) {
|
||||
- void* ptr = ti.pool_allocate(MAX_MEMTAG_MASSTREE_INTERNODE_ALLOCATION_SIZE,
|
||||
+ static internode<P>* make(uint32_t height, threadinfo& ti, void * allocated_internode = nullptr) {
|
||||
+ void* ptr = allocated_internode ?
|
||||
+ allocated_internode :
|
||||
+ ti.pool_allocate(MAX_MEMTAG_MASSTREE_INTERNODE_ALLOCATION_SIZE,
|
||||
memtag_masstree_internode);
|
||||
+ if (!ptr) {
|
||||
+ ti.set_last_error(MT_MERR_MAKE_INTERNODE);
|
||||
+ return nullptr;
|
||||
+ }
|
||||
internode<P>* n = new(ptr) internode<P>(height);
|
||||
assert(n);
|
||||
if (P::debug_level > 0)
|
||||
@@ -319,8 +325,12 @@ class leaf : public node_base<P> {
|
||||
}
|
||||
|
||||
static leaf<P>* make(int ksufsize, phantom_epoch_type phantom_epoch, threadinfo& ti) {
|
||||
- size_t sz = iceil(sizeof(leaf<P>) + std::min(ksufsize, 128), 64);
|
||||
+ size_t sz = MAX_MEMTAG_MASSTREE_LEAF_ALLOCATION_SIZE; // iceil(sizeof(leaf<P>) + std::min(ksufsize, 128), 64);
|
||||
void* ptr = ti.pool_allocate(sz, memtag_masstree_leaf);
|
||||
+ if (!ptr) {
|
||||
+ ti.set_last_error(MT_MERR_MAKE_LEAF);
|
||||
+ return nullptr;
|
||||
+ }
|
||||
leaf<P>* n = new(ptr) leaf<P>(sz, phantom_epoch);
|
||||
assert(n);
|
||||
if (P::debug_level > 0) {
|
||||
@@ -330,6 +340,10 @@ class leaf : public node_base<P> {
|
||||
}
|
||||
static leaf<P>* make_root(int ksufsize, leaf<P>* parent, threadinfo& ti) {
|
||||
leaf<P>* n = make(ksufsize, parent ? parent->phantom_epoch() : phantom_epoch_type(), ti);
|
||||
+ if (!n) {
|
||||
+ ti.set_last_error(MT_MERR_MAKE_ROOT_LEAF);
|
||||
+ return nullptr;
|
||||
+ }
|
||||
n->next_.ptr = n->prev_ = 0;
|
||||
n->ikey0_[0] = 0; // to avoid undefined behavior
|
||||
n->make_layer_root();
|
||||
@@ -413,7 +427,9 @@ class leaf : public node_base<P> {
|
||||
}
|
||||
Str ksuf(int p, int keylenx) const {
|
||||
(void) keylenx;
|
||||
- masstree_precondition(keylenx_has_ksuf(keylenx));
|
||||
+ // keylenx might not be equal to ksuf_keylenx as this operation might be called without holding leaf's lock
|
||||
+ // We allow it, and expect the caller to validate leaf's version and retry.
|
||||
+ //masstree_precondition(keylenx_has_ksuf(keylenx));
|
||||
return ksuf_ ? ksuf_->get(p) : iksuf_[0].get(p);
|
||||
}
|
||||
Str ksuf(int p) const {
|
||||
@@ -429,7 +445,7 @@ class leaf : public node_base<P> {
|
||||
return s.len == ka.suffix().len
|
||||
&& string_slice<uintptr_t>::equals_sloppy(s.s, ka.suffix().s, s.len);
|
||||
}
|
||||
- // Returns 1 if match & not layer, 0 if no match, <0 if match and layer
|
||||
+ // Returns 1 if match & not layer, 0 if no match, < 0 if match and layer
|
||||
int ksuf_matches(int p, const key_type& ka) const {
|
||||
int keylenx = keylenx_[p];
|
||||
if (keylenx < ksuf_keylenx)
|
||||
@@ -520,40 +536,55 @@ class leaf : public node_base<P> {
|
||||
modstate_ = modstate_deleted_layer;
|
||||
}
|
||||
|
||||
- inline void assign(int p, const key_type& ka, threadinfo& ti) {
|
||||
+ inline bool assign(int p, const key_type& ka, threadinfo& ti) {
|
||||
lv_[p] = leafvalue_type::make_empty();
|
||||
ikey0_[p] = ka.ikey();
|
||||
if (!ka.has_suffix()) {
|
||||
keylenx_[p] = ka.length();
|
||||
} else {
|
||||
keylenx_[p] = ksuf_keylenx;
|
||||
- assign_ksuf(p, ka.suffix(), false, ti);
|
||||
+ if (!assign_ksuf(p, ka.suffix(), false, ti)) {
|
||||
+ ti.set_last_error(MT_MERR_LEAF_ASSIGN);
|
||||
+ return false;
|
||||
+ }
|
||||
}
|
||||
+
|
||||
+ return true;
|
||||
}
|
||||
- inline void assign_initialize(int p, const key_type& ka, threadinfo& ti) {
|
||||
+ inline bool assign_initialize(int p, const key_type& ka, threadinfo& ti) {
|
||||
lv_[p] = leafvalue_type::make_empty();
|
||||
ikey0_[p] = ka.ikey();
|
||||
if (!ka.has_suffix()) {
|
||||
keylenx_[p] = ka.length();
|
||||
} else {
|
||||
keylenx_[p] = ksuf_keylenx;
|
||||
- assign_ksuf(p, ka.suffix(), true, ti);
|
||||
+ if (!assign_ksuf(p, ka.suffix(), true, ti)) {
|
||||
+ ti.set_last_error(MT_MERR_ASSIGN_INITALIZE_1);
|
||||
+ return false;
|
||||
+ }
|
||||
}
|
||||
+
|
||||
+ return true;
|
||||
}
|
||||
- inline void assign_initialize(int p, leaf<P>* x, int xp, threadinfo& ti) {
|
||||
+ inline bool assign_initialize(int p, leaf<P>* x, int xp, threadinfo& ti) {
|
||||
lv_[p] = x->lv_[xp];
|
||||
ikey0_[p] = x->ikey0_[xp];
|
||||
keylenx_[p] = x->keylenx_[xp];
|
||||
if (x->has_ksuf(xp)) {
|
||||
- assign_ksuf(p, x->ksuf(xp), true, ti);
|
||||
+ if (!assign_ksuf(p, x->ksuf(xp), true, ti)) {
|
||||
+ ti.set_last_error(MT_MERR_ASSIGN_INITALIZE_2);
|
||||
+ return false;
|
||||
+ }
|
||||
}
|
||||
+
|
||||
+ return true;
|
||||
}
|
||||
inline void assign_initialize_for_layer(int p, const key_type& ka) {
|
||||
assert(ka.has_suffix());
|
||||
ikey0_[p] = ka.ikey();
|
||||
keylenx_[p] = layer_keylenx;
|
||||
}
|
||||
- void assign_ksuf(int p, Str s, bool initializing, threadinfo& ti);
|
||||
+ bool assign_ksuf(int p, Str s, bool initializing, threadinfo& ti);
|
||||
|
||||
inline ikey_type ikey_after_insert(const permuter_type& perm, int i,
|
||||
const tcursor<P>* cursor) const;
|
||||
@@ -763,14 +794,14 @@ leaf<P>* leaf<P>::advance_to_key(const key_type& ka, nodeversion_type& v,
|
||||
positions [0,p) are ready: keysuffixes in that range are copied. In either
|
||||
case, the key at position p is NOT copied; it is assigned to @a s. */
|
||||
template <typename P>
|
||||
-void leaf<P>::assign_ksuf(int p, Str s, bool initializing, threadinfo& ti) {
|
||||
+bool leaf<P>::assign_ksuf(int p, Str s, bool initializing, threadinfo& ti) {
|
||||
if ((ksuf_ && ksuf_->assign(p, s))
|
||||
|| (extrasize64_ > 0 && iksuf_[0].assign(p, s)))
|
||||
{
|
||||
#if !(defined(__x86_64__) || defined(__x86__))
|
||||
fence();
|
||||
-#endif
|
||||
- return;
|
||||
+#endif
|
||||
+ return true;
|
||||
}
|
||||
external_ksuf_type* oksuf = ksuf_;
|
||||
|
||||
@@ -796,15 +827,19 @@ void leaf<P>::assign_ksuf(int p, Str s, bool initializing, threadinfo& ti) {
|
||||
sz = std::max(sz, oksuf->capacity());
|
||||
|
||||
void* ptr = ti.allocate(sz, memtag_masstree_ksuffixes, &sz);
|
||||
+ if (!ptr) {
|
||||
+ ti.set_last_error(MT_MERR_ASSIGN_KSUF);
|
||||
+ return false;
|
||||
+ }
|
||||
external_ksuf_type* nksuf = new(ptr) external_ksuf_type(width, sz);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
int mp = initializing ? i : perm[i];
|
||||
if (mp != p && has_ksuf(mp)) {
|
||||
- bool ok = nksuf->assign(mp, ksuf(mp));
|
||||
+ bool ok = nksuf->assign(mp, ksuf(mp)); // No memory allocation here
|
||||
assert(ok); (void) ok;
|
||||
}
|
||||
}
|
||||
- bool ok = nksuf->assign(p, s);
|
||||
+ bool ok = nksuf->assign(p, s); // No memory allocation here
|
||||
assert(ok); (void) ok;
|
||||
fence();
|
||||
|
||||
@@ -824,11 +859,12 @@ void leaf<P>::assign_ksuf(int p, Str s, bool initializing, threadinfo& ti) {
|
||||
if (oksuf)
|
||||
ti.deallocate_rcu(oksuf, oksuf->capacity(),
|
||||
memtag_masstree_ksuffixes);
|
||||
+ return true;
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
inline basic_table<P>::basic_table()
|
||||
- : root_(0) {
|
||||
+ : root_(nullptr) {
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
diff --git a/masstree_tcursor.hh b/masstree_tcursor.hh
|
||||
index 2442c9f..755588d 100644
|
||||
--- a/masstree_tcursor.hh
|
||||
+++ b/masstree_tcursor.hh
|
||||
@@ -106,22 +106,23 @@ class tcursor {
|
||||
static constexpr int new_nodes_size = 1; // unless we make a new trie newnodes will have at most 1 item
|
||||
typedef small_vector<std::pair<leaf_type*, nodeversion_value_type>, new_nodes_size> new_nodes_type;
|
||||
|
||||
+#ifndef MOT_OBSOLETE_CODE
|
||||
tcursor(basic_table<P>& table, Str str)
|
||||
: ka_(str), root_(table.fix_root()) {
|
||||
}
|
||||
tcursor(basic_table<P>& table, const char* s, int len)
|
||||
: ka_(s, len), root_(table.fix_root()) {
|
||||
}
|
||||
- tcursor(basic_table<P>& table, const unsigned char* s, int len)
|
||||
- : ka_(reinterpret_cast<const char*>(s), len), root_(table.fix_root()) {
|
||||
- }
|
||||
- tcursor(node_base<P>* root, const char* s, int len)
|
||||
- : ka_(s, len), root_(root) {
|
||||
- }
|
||||
tcursor(node_base<P>* root, const unsigned char* s, int len)
|
||||
: ka_(reinterpret_cast<const char*>(s), len), root_(root) {
|
||||
}
|
||||
-
|
||||
+#endif
|
||||
+ tcursor(basic_table<P>& table, const unsigned char* s, int len)
|
||||
+ : ka_(reinterpret_cast<const char*>(s), len), root_(table.fix_root()), root_ref_(table.root_ref()) {
|
||||
+ }
|
||||
+ tcursor(node_base<P>** root_ref, const char* s, int len)
|
||||
+ : ka_(s, len), root_(*root_ref), root_ref_(root_ref) {
|
||||
+ }
|
||||
inline bool has_value() const {
|
||||
return kx_.p >= 0;
|
||||
}
|
||||
@@ -148,13 +149,13 @@ class tcursor {
|
||||
inline nodeversion_value_type updated_version_value() const {
|
||||
return updated_v_;
|
||||
}
|
||||
-
|
||||
+#ifndef MOT_OBSOLETE_CODE
|
||||
inline const new_nodes_type &new_nodes() const {
|
||||
return new_nodes_;
|
||||
}
|
||||
-
|
||||
+#endif
|
||||
inline bool find_locked(threadinfo& ti);
|
||||
- inline bool find_insert(threadinfo& ti);
|
||||
+ inline bool find_insert(threadinfo& ti, bool & found);
|
||||
|
||||
inline void finish(int answer, threadinfo& ti);
|
||||
|
||||
@@ -166,13 +167,16 @@ class tcursor {
|
||||
key_type ka_;
|
||||
key_indexed_position kx_;
|
||||
node_base<P>* root_;
|
||||
+ node_base<P>** root_ref_;
|
||||
int state_;
|
||||
|
||||
- leaf_type* original_n_;
|
||||
+ leaf_type* original_n_ = nullptr;
|
||||
nodeversion_value_type original_v_;
|
||||
nodeversion_value_type updated_v_;
|
||||
- new_nodes_type new_nodes_;
|
||||
|
||||
+#ifndef MOT_OBSOLETE_CODE
|
||||
+ new_nodes_type new_nodes_;
|
||||
+#endif
|
||||
inline node_type* reset_retry() {
|
||||
ka_.unshift_all();
|
||||
return root_;
|
||||
@@ -180,6 +184,7 @@ class tcursor {
|
||||
|
||||
bool make_new_layer(threadinfo& ti);
|
||||
bool make_split(threadinfo& ti);
|
||||
+ void release_internodes(internode_type * internodes_array[], int start, int end, threadinfo& ti);
|
||||
friend class leaf<P>;
|
||||
inline void finish_insert();
|
||||
inline bool finish_remove(threadinfo& ti);
|
||||
@@ -191,7 +196,7 @@ class tcursor {
|
||||
* If removing a leaf in layer 0, @a prefix is empty.
|
||||
* If removing, for example, the node containing key "01234567ABCDEF" in the layer-1 tree
|
||||
* rooted at "01234567", then @a prefix should equal "01234567". */
|
||||
- static bool remove_leaf(leaf_type* leaf, node_type* root,
|
||||
+ static bool remove_leaf(leaf_type* leaf, node_type** root_ref,
|
||||
Str prefix, threadinfo& ti);
|
||||
|
||||
bool gc_layer(threadinfo& ti);
|
||||
diff --git a/mot_masstree_config.hpp b/mot_masstree_config.hpp
|
||||
index bec2ec8..fe3930b 100644
|
||||
--- a/mot_masstree_config.hpp
|
||||
+++ b/mot_masstree_config.hpp
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef MOT_MASSTREE_CONFIG_HPP
|
||||
#define MOT_MASSTREE_CONFIG_HPP
|
||||
|
||||
+// Ignore masstree code which is obsolete in MOT
|
||||
+#define MOT_OBSOLETE_CODE 1
|
||||
+
|
||||
#define MOT_HAVE_CXX_TEMPLATE_ALIAS 1
|
||||
#define MOT_HAVE_INT64_T_IS_LONG 1
|
||||
#define MOT_HAVE_SIZE_T_IS_UNSIGNED_LONG 1
|
||||
@@ -58,7 +61,7 @@
|
||||
#define MOT_SIZEOF_LONG_LONG 8
|
||||
#define MOT_SIZEOF_SHORT 2
|
||||
#define MOT_WORDS_BIGENDIAN_SET 1
|
||||
-
|
||||
+/*
|
||||
#define masstree_invariant(x, ...) \
|
||||
do { \
|
||||
} while (0)
|
||||
@@ -66,6 +69,12 @@
|
||||
#define masstree_precondition(x, ...) \
|
||||
do { \
|
||||
} while (0)
|
||||
+*/
|
||||
+
|
||||
+#define masstree_invariant(x, ...) assert(x)
|
||||
+#define masstree_precondition(x, ...) assert(x)
|
||||
+
|
||||
+
|
||||
|
||||
#ifndef invariant
|
||||
#define invariant masstree_invariant
|
||||
--
|
||||
1.8.3.1
|
||||
|
@ -1,449 +0,0 @@
|
||||
From 62fcebd4a8ac1a60acbf1f227a57be5b8d981c8e Mon Sep 17 00:00:00 2001
|
||||
From: Vinoth Veeraraghavan <vinoth.veeraraghavan@hotmail.com>
|
||||
Date: Thu, 14 Jul 2022 18:55:08 +0300
|
||||
Subject: [PATCH] Clean masstree code
|
||||
|
||||
More detail: Clean masstree code
|
||||
---
|
||||
kvthread.hh | 27 +++--
|
||||
masstree.hh | 15 +--
|
||||
masstree_config.h | 118 +++++++++++----------
|
||||
masstree_insert.hh | 4 +-
|
||||
masstree_split.hh | 2 +-
|
||||
masstree_tcursor.hh | 6 +-
|
||||
mot_masstree_config.hpp | 99 -----------------
|
||||
7 files changed, 83 insertions(+), 188 deletions(-)
|
||||
delete mode 100644 mot_masstree_config.hpp
|
||||
|
||||
diff --git a/kvthread.hh b/kvthread.hh
|
||||
index 364cd44..01d6919 100644
|
||||
--- a/kvthread.hh
|
||||
+++ b/kvthread.hh
|
||||
@@ -69,11 +69,6 @@ enum {
|
||||
|
||||
class threadinfo;
|
||||
class loginfo;
|
||||
-namespace MOT
|
||||
-{
|
||||
- class MasstreePrimaryIndex;
|
||||
- class GcManager;
|
||||
-};
|
||||
|
||||
extern __thread threadinfo * mtSessionThreadInfo;
|
||||
|
||||
@@ -284,7 +279,7 @@ class alignas(64) threadinfo {
|
||||
void* p = NULL;
|
||||
int nl = (sz + memdebug_size + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE;
|
||||
if (use_pool()) {
|
||||
- masstree_invariant(false); // mot code should not reach here
|
||||
+ masstree_invariant(false); // internal memory pool is currently disabled
|
||||
assert(nl <= pool_max_nlines);
|
||||
if (unlikely(!pool_[nl - 1]))
|
||||
refill_pool(nl);
|
||||
@@ -308,10 +303,11 @@ class alignas(64) threadinfo {
|
||||
assert(p && nl <= pool_max_nlines);
|
||||
p = memdebug::check_free(p, sz, memtag(tag + nl));
|
||||
if (use_pool()) {
|
||||
+ masstree_invariant(false); // internal memory pool is currently disabled
|
||||
*reinterpret_cast<void **>(p) = pool_[nl - 1];
|
||||
pool_[nl - 1] = p;
|
||||
} else
|
||||
- deallocate(p, sz, tag); // mot memory deallocation
|
||||
+ deallocate(p, sz, tag); // external memory pool deallocation
|
||||
mark(threadcounter(tc_alloc + (tag > memtag_value)),
|
||||
-nl * CACHE_LINE_SIZE);
|
||||
}
|
||||
@@ -380,15 +376,16 @@ class alignas(64) threadinfo {
|
||||
void set_rcu_free_count(int rcu_count) { rcu_free_count = rcu_count; }
|
||||
int get_rcu_free_count() { return rcu_free_count; }
|
||||
|
||||
- void set_gc_session(MOT::GcManager* gc_session);
|
||||
- MOT::GcManager * get_gc_session();
|
||||
+ void set_gc_session(void * gc_session);
|
||||
+ void * get_gc_session();
|
||||
|
||||
inline uint32_t get_occupied_elements() { return total_limbo_inuse_elements; }
|
||||
|
||||
- void set_working_index (MOT::MasstreePrimaryIndex * index) { cur_working_index = (MOT::MasstreePrimaryIndex *)index; }
|
||||
- MOT::MasstreePrimaryIndex * get_working_index () { return cur_working_index; }
|
||||
+ void set_working_index (void * index) { cur_working_index = index; }
|
||||
+ void * get_working_index () { return cur_working_index; }
|
||||
|
||||
- // This function is now used to defer between Masstree internal pools (use_pool == true) vs MOT pools\slab allocators (use_pool == false)
|
||||
+ // This function is now used to defer between Masstree internal memory pool (use_pool == true) vs external memory pool (use_pool == false)
|
||||
+ // Masstree internal memory pool is currently disabled
|
||||
static bool use_pool() {
|
||||
#if ENABLE_ASSERTIONS
|
||||
return !no_pool_value;
|
||||
@@ -403,7 +400,7 @@ class alignas(64) threadinfo {
|
||||
}
|
||||
|
||||
private:
|
||||
- MOT::MasstreePrimaryIndex * cur_working_index;
|
||||
+ void * cur_working_index;
|
||||
int last_error = MT_MERR_OK;
|
||||
std::vector<struct rcu_entry> dealloc_rcu;
|
||||
union {
|
||||
@@ -427,7 +424,7 @@ class alignas(64) threadinfo {
|
||||
int rcu_free_count;
|
||||
mt_limbo_group* limbo_head_;
|
||||
mt_limbo_group* limbo_tail_;
|
||||
- MOT::GcManager* gc_session_;
|
||||
+ void * gc_session_;
|
||||
uint32_t total_limbo_inuse_elements;
|
||||
|
||||
mutable kvtimestamp_t ts_;
|
||||
@@ -458,7 +455,7 @@ class alignas(64) threadinfo {
|
||||
|
||||
void record_rcu(void* ptr, int size, memtag tag) {
|
||||
if (unlikely(use_pool())) {
|
||||
- masstree_invariant(false); // mot code should not reach here
|
||||
+ masstree_invariant(false); // internal memory pool is currently disabled
|
||||
if (limbo_tail_->tail_ + 2 > limbo_tail_->capacity)
|
||||
refill_rcu();
|
||||
uint64_t epoch = ng_getGlobalEpoch();
|
||||
diff --git a/masstree.hh b/masstree.hh
|
||||
index 89af0ee..955a5bc 100644
|
||||
--- a/masstree.hh
|
||||
+++ b/masstree.hh
|
||||
@@ -20,12 +20,6 @@
|
||||
#include "ksearch.hh"
|
||||
#include "kvthread.hh"
|
||||
|
||||
-namespace MOT {
|
||||
-class Key;
|
||||
-}
|
||||
-
|
||||
-using namespace MOT;
|
||||
-
|
||||
namespace Masstree {
|
||||
using lcdf::Str;
|
||||
using lcdf::String;
|
||||
@@ -62,8 +56,7 @@ template <typename P> class basic_table;
|
||||
template <typename P> class unlocked_tcursor;
|
||||
template <typename P> class tcursor;
|
||||
|
||||
-template<bool CONST_ITERATOR, bool FORWARD, typename P>
|
||||
-class MasstreeIterator;
|
||||
+template <bool CONST_ITERATOR, bool FORWARD, typename P> class MasstreeIterator;
|
||||
|
||||
template <typename P>
|
||||
class basic_table {
|
||||
@@ -78,12 +71,12 @@ class basic_table {
|
||||
typedef MasstreeIterator<false, true, P> ForwardIterator;
|
||||
typedef MasstreeIterator<false, false, P> ReverseIterator;
|
||||
|
||||
- void find(MOT::Key const* const& key, void*& output, bool& result, const uint32_t& pid) const;
|
||||
+ void find(const uint8_t* key, const uint32_t key_len, void*& output, bool& result, const uint32_t& pid) const;
|
||||
|
||||
- void iteratorScan(const char * keybuf, uint32_t keylen, const bool& matchKey, Iterator* const& it, const bool& forwardDirection,
|
||||
+ void iteratorScan(const char * keybuf, uint32_t keylen, const bool& matchKey, void* const& it, const bool& forwardDirection,
|
||||
bool& result, const uint32_t& pid);
|
||||
|
||||
- void *insert(MOT::Key const* const& key, void* const& entry, bool& result, const uint32_t& pid);
|
||||
+ void *insert(const uint8_t* key, const uint32_t key_len, void* const& entry, bool& result, const uint32_t& pid);
|
||||
void *remove(uint8_t const *const &key, uint32_t length, bool &result, const uint32_t &pid);
|
||||
bool init(const uint16_t keyLength, const std::string& name, destroy_value_cb_func destroyValue_CB = NULL);
|
||||
int getMemtagMaxSize(enum memtag tag);
|
||||
diff --git a/masstree_config.h b/masstree_config.h
|
||||
index ecfaf2b..d5a3a17 100644
|
||||
--- a/masstree_config.h
|
||||
+++ b/masstree_config.h
|
||||
@@ -1,62 +1,66 @@
|
||||
-/*
|
||||
- * Copyright (c) 2020 Huawei Technologies Co.,Ltd.
|
||||
- *
|
||||
- * openGauss is licensed under Mulan PSL v2.
|
||||
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
- * You may obtain a copy of Mulan PSL v2 at:
|
||||
- *
|
||||
- * http://license.coscl.org.cn/MulanPSL2
|
||||
- *
|
||||
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
- * See the Mulan PSL v2 for more details.
|
||||
- * -------------------------------------------------------------------------
|
||||
- *
|
||||
- * config.h
|
||||
- * Masstree index configurations template.
|
||||
- *
|
||||
- * IDENTIFICATION
|
||||
- * src/gausskernel/storage/mot/core/src/storage/index/masstree/config.h
|
||||
- *
|
||||
- * -------------------------------------------------------------------------
|
||||
- */
|
||||
-
|
||||
-#include "mot_masstree_config.hpp"
|
||||
-
|
||||
#ifndef MASSTREE_CONFIG_H
|
||||
#define MASSTREE_CONFIG_H
|
||||
|
||||
-#define HAVE_CXX_TEMPLATE_ALIAS MOT_HAVE_CXX_TEMPLATE_ALIAS
|
||||
-#define HAVE_INT64_T_IS_LONG MOT_HAVE_INT64_T_IS_LONG
|
||||
-#define HAVE_SIZE_T_IS_UNSIGNED_LONG MOT_HAVE_SIZE_T_IS_UNSIGNED_LONG
|
||||
-#define HAVE_STD_HASH MOT_HAVE_STD_HASH
|
||||
-#define HAVE_STD_IS_TRIVIALLY_COPYABLE MOT_HAVE_STD_IS_TRIVIALLY_COPYABLE
|
||||
-#define HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE MOT_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
|
||||
-#define HAVE_SUPERPAGE MOT_HAVE_SUPERPAGE
|
||||
-#define HAVE_TYPE_TRAITS MOT_HAVE_TYPE_TRAITS
|
||||
-#define HAVE_UNALIGNED_ACCESS MOT_HAVE_UNALIGNED_ACCESS
|
||||
-#define HAVE___BUILTIN_CLZ MOT_HAVE___BUILTIN_CLZ
|
||||
-#define HAVE___BUILTIN_CLZL MOT_HAVE___BUILTIN_CLZL
|
||||
-#define HAVE___BUILTIN_CLZLL MOT_HAVE___BUILTIN_CLZLL
|
||||
-#define HAVE___BUILTIN_CTZ MOT_HAVE___BUILTIN_CTZ
|
||||
-#define HAVE___BUILTIN_CTZL MOT_HAVE___BUILTIN_CTZL
|
||||
-#define HAVE___BUILTIN_CTZLL MOT_HAVE___BUILTIN_CTZLL
|
||||
-#define HAVE___HAS_TRIVIAL_COPY MOT_HAVE___HAS_TRIVIAL_COPY
|
||||
-#define HAVE___HAS_TRIVIAL_DESTRUCTOR MOT_HAVE___HAS_TRIVIAL_DESTRUCTOR
|
||||
-#define HAVE___SYNC_BOOL_COMPARE_AND_SWAP MOT_HAVE___SYNC_BOOL_COMPARE_AND_SWAP
|
||||
-#define HAVE___SYNC_BOOL_COMPARE_AND_SWAP_8 MOT_HAVE___SYNC_BOOL_COMPARE_AND_SWAP_8
|
||||
-#define HAVE___SYNC_FETCH_AND_ADD MOT_HAVE___SYNC_FETCH_AND_ADD
|
||||
-#define HAVE___SYNC_FETCH_AND_ADD_8 MOT_HAVE___SYNC_FETCH_AND_ADD_8
|
||||
-#define HAVE___SYNC_FETCH_AND_OR MOT_HAVE___SYNC_FETCH_AND_OR
|
||||
-#define HAVE___SYNC_FETCH_AND_OR_8 MOT_HAVE___SYNC_FETCH_AND_OR_8
|
||||
-#define HAVE___SYNC_VAL_COMPARE_AND_SWAP MOT_HAVE___SYNC_VAL_COMPARE_AND_SWAP
|
||||
-#define HAVE___SYNC_VAL_COMPARE_AND_SWAP_8 MOT_HAVE___SYNC_VAL_COMPARE_AND_SWAP_8
|
||||
-#define MASSTREE_MAXKEYLEN MOT_MASSTREE_MAXKEYLEN
|
||||
-#define SIZEOF_INT MOT_SIZEOF_INT
|
||||
-#define SIZEOF_LONG MOT_SIZEOF_LONG
|
||||
-#define SIZEOF_LONG_LONG MOT_SIZEOF_LONG_LONG
|
||||
-#define SIZEOF_SHORT MOT_SIZEOF_SHORT
|
||||
-#define WORDS_BIGENDIAN_SET MOT_WORDS_BIGENDIAN_SET
|
||||
+#define HAVE_CXX_TEMPLATE_ALIAS 1
|
||||
+#define HAVE_INT64_T_IS_LONG 1
|
||||
+#define HAVE_SIZE_T_IS_UNSIGNED_LONG 1
|
||||
+#define HAVE_STD_HASH 1
|
||||
+#define HAVE_STD_IS_TRIVIALLY_COPYABLE 1
|
||||
+#define HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
|
||||
+#define HAVE_SUPERPAGE 1
|
||||
+#define HAVE_TYPE_TRAITS 1
|
||||
+#define HAVE_UNALIGNED_ACCESS 0
|
||||
+#define HAVE___BUILTIN_CLZ 1
|
||||
+#define HAVE___BUILTIN_CLZL 1
|
||||
+#define HAVE___BUILTIN_CLZLL 1
|
||||
+#define HAVE___BUILTIN_CTZ 1
|
||||
+#define HAVE___BUILTIN_CTZL 1
|
||||
+#define HAVE___BUILTIN_CTZLL 1
|
||||
+#define HAVE___HAS_TRIVIAL_COPY 1
|
||||
+#define HAVE___HAS_TRIVIAL_DESTRUCTOR 1
|
||||
+#define HAVE___SYNC_BOOL_COMPARE_AND_SWAP 1
|
||||
+#define HAVE___SYNC_BOOL_COMPARE_AND_SWAP_8 1
|
||||
+#define HAVE___SYNC_FETCH_AND_ADD 1
|
||||
+#define HAVE___SYNC_FETCH_AND_ADD_8 1
|
||||
+#define HAVE___SYNC_FETCH_AND_OR 1
|
||||
+#define HAVE___SYNC_FETCH_AND_OR_8 1
|
||||
+#define HAVE___SYNC_VAL_COMPARE_AND_SWAP 1
|
||||
+#define HAVE___SYNC_VAL_COMPARE_AND_SWAP_8 1
|
||||
+
|
||||
+/* Maximum key length */
|
||||
+#define MASSTREE_MAXKEYLEN 256U
|
||||
+
|
||||
+#define SIZEOF_INT 4
|
||||
+#define SIZEOF_LONG 8
|
||||
+#define SIZEOF_LONG_LONG 8
|
||||
+#define SIZEOF_SHORT 2
|
||||
+#define WORDS_BIGENDIAN_SET 1
|
||||
+
|
||||
+#define MASSTREE_OBSOLETE_CODE 1
|
||||
|
||||
+#define masstree_invariant(x, ...) assert(x)
|
||||
+#define masstree_precondition(x, ...) assert(x)
|
||||
+
|
||||
+
|
||||
+
|
||||
+#ifndef invariant
|
||||
+#define invariant masstree_invariant
|
||||
+#endif
|
||||
+#ifndef precondition
|
||||
+#define precondition masstree_precondition
|
||||
#endif
|
||||
+
|
||||
+#ifndef CACHE_LINE_SIZE
|
||||
+#define CACHE_LINE_SIZE 64
|
||||
+#endif
|
||||
+
|
||||
+#ifndef PRIu64
|
||||
+#if HAVE_SIZE_T_IS_UNSIGNED_LONG_LONG
|
||||
+#define PRIu64 "llu"
|
||||
+#else
|
||||
+#define PRIu64 "lu"
|
||||
+#endif
|
||||
+#endif
|
||||
+
|
||||
+
|
||||
+#endif // MASSTREE_CONFIG_H
|
||||
diff --git a/masstree_insert.hh b/masstree_insert.hh
|
||||
index e641f03..9f21bca 100644
|
||||
--- a/masstree_insert.hh
|
||||
+++ b/masstree_insert.hh
|
||||
@@ -98,7 +98,7 @@ bool tcursor<P>::make_new_layer(threadinfo& ti) {
|
||||
twig_head = nl;
|
||||
nl->permutation_ = permuter_type::make_sorted(1);
|
||||
twig_tail = nl;
|
||||
-#ifndef MOT_OBSOLETE_CODE
|
||||
+#ifndef MASSTREE_OBSOLETE_CODE
|
||||
new_nodes_.emplace_back(nl, nl->full_unlocked_version_value());
|
||||
#endif
|
||||
oka.shift();
|
||||
@@ -213,7 +213,7 @@ inline void tcursor<P>::finish(int state, threadinfo& ti)
|
||||
// we finally know this!
|
||||
if (n_ == original_n_)
|
||||
updated_v_ = n_->full_unlocked_version_value();
|
||||
-#ifndef MOT_OBSOLETE_CODE
|
||||
+#ifndef MASSTREE_OBSOLETE_CODE
|
||||
else
|
||||
new_nodes_.emplace_back(n_, n_->full_unlocked_version_value());
|
||||
#endif
|
||||
diff --git a/masstree_split.hh b/masstree_split.hh
|
||||
index 42b012b..2d53de6 100644
|
||||
--- a/masstree_split.hh
|
||||
+++ b/masstree_split.hh
|
||||
@@ -363,7 +363,7 @@ bool tcursor<P>::make_split(threadinfo& ti)
|
||||
ti.set_last_error(MT_MERR_MAKE_SPLIT_ASSIGN_SUFFIX);
|
||||
rc = false;
|
||||
}
|
||||
-#ifndef MOT_OBSOLETE_CODE
|
||||
+#ifndef MASSTREE_OBSOLETE_CODE
|
||||
new_nodes_.emplace_back(nr, nr->full_unlocked_version_value());
|
||||
#endif
|
||||
} else {
|
||||
diff --git a/masstree_tcursor.hh b/masstree_tcursor.hh
|
||||
index 755588d..73231b8 100644
|
||||
--- a/masstree_tcursor.hh
|
||||
+++ b/masstree_tcursor.hh
|
||||
@@ -106,7 +106,7 @@ class tcursor {
|
||||
static constexpr int new_nodes_size = 1; // unless we make a new trie newnodes will have at most 1 item
|
||||
typedef small_vector<std::pair<leaf_type*, nodeversion_value_type>, new_nodes_size> new_nodes_type;
|
||||
|
||||
-#ifndef MOT_OBSOLETE_CODE
|
||||
+#ifndef MASSTREE_OBSOLETE_CODE
|
||||
tcursor(basic_table<P>& table, Str str)
|
||||
: ka_(str), root_(table.fix_root()) {
|
||||
}
|
||||
@@ -149,7 +149,7 @@ class tcursor {
|
||||
inline nodeversion_value_type updated_version_value() const {
|
||||
return updated_v_;
|
||||
}
|
||||
-#ifndef MOT_OBSOLETE_CODE
|
||||
+#ifndef MASSTREE_OBSOLETE_CODE
|
||||
inline const new_nodes_type &new_nodes() const {
|
||||
return new_nodes_;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ class tcursor {
|
||||
nodeversion_value_type original_v_;
|
||||
nodeversion_value_type updated_v_;
|
||||
|
||||
-#ifndef MOT_OBSOLETE_CODE
|
||||
+#ifndef MASSTREE_OBSOLETE_CODE
|
||||
new_nodes_type new_nodes_;
|
||||
#endif
|
||||
inline node_type* reset_retry() {
|
||||
diff --git a/mot_masstree_config.hpp b/mot_masstree_config.hpp
|
||||
deleted file mode 100644
|
||||
index fe3930b..0000000
|
||||
--- a/mot_masstree_config.hpp
|
||||
+++ /dev/null
|
||||
@@ -1,99 +0,0 @@
|
||||
-/*
|
||||
- * Copyright (c) 2020 Huawei Technologies Co.,Ltd.
|
||||
- *
|
||||
- * openGauss is licensed under Mulan PSL v2.
|
||||
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
- * You may obtain a copy of Mulan PSL v2 at:
|
||||
- *
|
||||
- * http://license.coscl.org.cn/MulanPSL2
|
||||
- *
|
||||
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
- * See the Mulan PSL v2 for more details.
|
||||
- * -------------------------------------------------------------------------
|
||||
- *
|
||||
- * mot_masstree_config.hpp
|
||||
- * MOT configurations for Masstree index.
|
||||
- *
|
||||
- * IDENTIFICATION
|
||||
- * src/gausskernel/storage/mot/core/src/storage/index/masstree/mot_masstree_config.hpp
|
||||
- *
|
||||
- * -------------------------------------------------------------------------
|
||||
- */
|
||||
-
|
||||
-#ifndef MOT_MASSTREE_CONFIG_HPP
|
||||
-#define MOT_MASSTREE_CONFIG_HPP
|
||||
-
|
||||
-// Ignore masstree code which is obsolete in MOT
|
||||
-#define MOT_OBSOLETE_CODE 1
|
||||
-
|
||||
-#define MOT_HAVE_CXX_TEMPLATE_ALIAS 1
|
||||
-#define MOT_HAVE_INT64_T_IS_LONG 1
|
||||
-#define MOT_HAVE_SIZE_T_IS_UNSIGNED_LONG 1
|
||||
-#define MOT_HAVE_STD_HASH 1
|
||||
-#define MOT_HAVE_STD_IS_TRIVIALLY_COPYABLE 1
|
||||
-#define MOT_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
|
||||
-#define MOT_HAVE_SUPERPAGE 1
|
||||
-#define MOT_HAVE_TYPE_TRAITS 1
|
||||
-#define MOT_HAVE_UNALIGNED_ACCESS 0
|
||||
-#define MOT_HAVE___BUILTIN_CLZ 1
|
||||
-#define MOT_HAVE___BUILTIN_CLZL 1
|
||||
-#define MOT_HAVE___BUILTIN_CLZLL 1
|
||||
-#define MOT_HAVE___BUILTIN_CTZ 1
|
||||
-#define MOT_HAVE___BUILTIN_CTZL 1
|
||||
-#define MOT_HAVE___BUILTIN_CTZLL 1
|
||||
-#define MOT_HAVE___HAS_TRIVIAL_COPY 1
|
||||
-#define MOT_HAVE___HAS_TRIVIAL_DESTRUCTOR 1
|
||||
-#define MOT_HAVE___SYNC_BOOL_COMPARE_AND_SWAP 1
|
||||
-#define MOT_HAVE___SYNC_BOOL_COMPARE_AND_SWAP_8 1
|
||||
-#define MOT_HAVE___SYNC_FETCH_AND_ADD 1
|
||||
-#define MOT_HAVE___SYNC_FETCH_AND_ADD_8 1
|
||||
-#define MOT_HAVE___SYNC_FETCH_AND_OR 1
|
||||
-#define MOT_HAVE___SYNC_FETCH_AND_OR_8 1
|
||||
-#define MOT_HAVE___SYNC_VAL_COMPARE_AND_SWAP 1
|
||||
-#define MOT_HAVE___SYNC_VAL_COMPARE_AND_SWAP_8 1
|
||||
-
|
||||
-/* Maximum key length */
|
||||
-#define MOT_MASSTREE_MAXKEYLEN MAX_KEY_SIZE
|
||||
-#define MOT_SIZEOF_INT 4
|
||||
-#define MOT_SIZEOF_LONG 8
|
||||
-#define MOT_SIZEOF_LONG_LONG 8
|
||||
-#define MOT_SIZEOF_SHORT 2
|
||||
-#define MOT_WORDS_BIGENDIAN_SET 1
|
||||
-/*
|
||||
-#define masstree_invariant(x, ...) \
|
||||
- do { \
|
||||
- } while (0)
|
||||
-
|
||||
-#define masstree_precondition(x, ...) \
|
||||
- do { \
|
||||
- } while (0)
|
||||
-*/
|
||||
-
|
||||
-#define masstree_invariant(x, ...) assert(x)
|
||||
-#define masstree_precondition(x, ...) assert(x)
|
||||
-
|
||||
-
|
||||
-
|
||||
-#ifndef invariant
|
||||
-#define invariant masstree_invariant
|
||||
-#endif
|
||||
-#ifndef precondition
|
||||
-#define precondition masstree_precondition
|
||||
-#endif
|
||||
-
|
||||
-#ifndef CACHE_LINE_SIZE
|
||||
-#define CACHE_LINE_SIZE 64
|
||||
-#endif
|
||||
-
|
||||
-#ifndef PRIu64
|
||||
-#if HAVE_SIZE_T_IS_UNSIGNED_LONG_LONG
|
||||
-#define PRIu64 "llu"
|
||||
-#else
|
||||
-#define PRIu64 "lu"
|
||||
-#endif
|
||||
-#endif
|
||||
-
|
||||
-
|
||||
-#endif // MOT_MASSTREE_CONFIG_HPP
|
||||
--
|
||||
1.8.3.1
|
||||
|
@ -1,153 +0,0 @@
|
||||
From a702402ec8849b6787bc4da51b785d1dbb0556b8 Mon Sep 17 00:00:00 2001
|
||||
From: Vinoth Veeraraghavan <vinoth.veeraraghavan@hotmail.com>
|
||||
Date: Wed, 4 Jan 2023 10:14:23 +0800
|
||||
Subject: [PATCH] Optimization in split flow
|
||||
|
||||
---
|
||||
kvthread.hh | 6 ++++--
|
||||
masstree_split.hh | 54 +++++++++++++++++++++--------------------------
|
||||
2 files changed, 28 insertions(+), 32 deletions(-)
|
||||
|
||||
diff --git a/kvthread.hh b/kvthread.hh
|
||||
index 01d6919..63df4c4 100644
|
||||
--- a/kvthread.hh
|
||||
+++ b/kvthread.hh
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
enum {
|
||||
MT_MERR_OK = 0,
|
||||
+ // Errors that will cause operation failure. bad flows are handled
|
||||
MT_MERR_MAKE_SPLIT_PRE_ALLOC = 1,
|
||||
MT_MERR_MAKE_SPLIT_LEAF_ALLOC = 2,
|
||||
MT_MERR_MAKE_NEW_LAYER_LEAF_ALLOC_1 = 3,
|
||||
@@ -43,6 +44,8 @@ enum {
|
||||
|
||||
// Errors that are being handled internally (Operation should succeed even if last error contains them)
|
||||
MT_MERR_NON_DISRUPTIVE_ERRORS = 15,
|
||||
+ MT_MERR_MAKE_INTERNODE_USE_RESERVED = 16,
|
||||
+ MT_MERR_MAKE_INTERNODE_USE_RESERVED_2 = 17,
|
||||
|
||||
// We should not reach the following errors as they should be covered with other errors in more upper layer
|
||||
MT_MERR_NOT_RETURNED_TO_USER_ERRORS = 20,
|
||||
@@ -59,7 +62,6 @@ enum {
|
||||
MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_NOT_EXPECTED,
|
||||
MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_NOT_EXPECTED_2,
|
||||
MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_EMPTY_PRE_ALLOC_NOT_EXPECTED,
|
||||
- MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_EMPTY_PRE_ALLOC_NOT_EXPECTED_2,
|
||||
|
||||
MT_MERR_NOT_IN_USE_LAST_ENTRY = 40
|
||||
};
|
||||
@@ -84,7 +86,7 @@ extern volatile mrcu_epoch_type active_epoch;
|
||||
#define MAX_MEMTAG_MASSTREE_LIMBO_GROUP_ALLOCATION_SIZE sizeof(mt_limbo_group)
|
||||
|
||||
// Upper bound for the ksuffixes structure max size.
|
||||
-#define MAX_MEMTAG_MASSTREE_KSUFFIXES_ALLOCATION_SIZE(width) iceil_log2(leaf<P>::external_ksuf_type::safe_size(width, MAX_KEY_SIZE * width));
|
||||
+#define MAX_MEMTAG_MASSTREE_KSUFFIXES_ALLOCATION_SIZE(width) iceil_log2(leaf<P>::external_ksuf_type::safe_size(width, MASSTREE_MAXKEYLEN * width));
|
||||
|
||||
inline uint64_t ng_getGlobalEpoch() {
|
||||
return globalepoch;
|
||||
diff --git a/masstree_split.hh b/masstree_split.hh
|
||||
index 2d53de6..a477757 100644
|
||||
--- a/masstree_split.hh
|
||||
+++ b/masstree_split.hh
|
||||
@@ -199,7 +199,6 @@ bool tcursor<P>::make_split(threadinfo& ti)
|
||||
// the ikey_bound). But in the latter case, perhaps we can rearrange the
|
||||
// permutation to do an insert instead.
|
||||
|
||||
- //IDAN: LEARN: as we might fail in case the last available slot is 0, why not replace the condition to (n_->size() < n_->width -1) ?
|
||||
if (n_->size() < n_->width) {
|
||||
permuter_type perm(n_->permutation_);
|
||||
perm.exchange(perm.size(), n_->width - 1);
|
||||
@@ -217,21 +216,7 @@ bool tcursor<P>::make_split(threadinfo& ti)
|
||||
|
||||
bool rc = true;
|
||||
|
||||
- // 2 optimizations that can reduce the number of internodes allocations:
|
||||
- // 1. In n_ does not have parent, only 1 internode is required (rare case - only on first split)
|
||||
- // 2. In case n_'s parent has extra place, and it's height is 1, we dont need internodes at all (common case, but requires early lock of n_'s parent)
|
||||
- node_type* l_root = n_;
|
||||
-
|
||||
- while (!l_root->is_root()) {
|
||||
- if (n_ != l_root) {
|
||||
- l_root->stable_annotated(ti.stable_fence());
|
||||
- }
|
||||
- l_root = l_root->maybe_parent();
|
||||
- }
|
||||
-
|
||||
- // l_root->height_ is the layer real height or higher.
|
||||
- uint32_t layer_height = l_root->isleaf() ? 1 : ((internode_type *)l_root)->height_;
|
||||
- int reserved_nodes = layer_height + 5; // add 5 extra nodes (extra 5 layers in single b-tree)
|
||||
+ int reserved_nodes = 2;
|
||||
internode_type * preallocated_internodes[reserved_nodes + 1] = { 0 };
|
||||
int cur_cache_index = 0;
|
||||
|
||||
@@ -274,27 +259,35 @@ bool tcursor<P>::make_split(threadinfo& ti)
|
||||
while (true) {
|
||||
masstree_invariant(!n->concurrent || (n->locked() && child->locked() && (n->isleaf() || n->splitting())));
|
||||
internode_type *next_child = 0;
|
||||
-
|
||||
internode_type *p = n->locked_parent(ti);
|
||||
|
||||
+ if (cur_cache_index == reserved_nodes) {
|
||||
+ // Should never happen with pre-allocated internodes (we should have enough reserved nodes). bad flow is not handled
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_EMPTY_PRE_ALLOC_NOT_EXPECTED);
|
||||
+ }
|
||||
+
|
||||
int kp = -1;
|
||||
if (n->parent_exists(p)) {
|
||||
kp = internode_type::bound_type::upper(xikey[sense], *p);
|
||||
p->mark_insert();
|
||||
}
|
||||
|
||||
- if (kp < 0 || p->height_ > height + 1) {
|
||||
+ // If cur_cache_index == 1, reserved internode was used on last loop due to memory allocation failure.
|
||||
+ // In this case, we have only 1 reserved internode left, so stop climbing and add the new internode in the current layer
|
||||
+ if (kp < 0 || p->height_ > height + 1 || cur_cache_index == 1) {
|
||||
masstree_invariant(preallocated_internodes[cur_cache_index]);
|
||||
- internode_type *nn = internode_type::make(height + 1, ti, preallocated_internodes[cur_cache_index++]);
|
||||
+ internode_type *nn = internode_type::make(height + 1, ti, nullptr);
|
||||
if (!nn) {
|
||||
- // Should never happen with pre-allocated internodes. bad flow is not handled
|
||||
- ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_NOT_EXPECTED);
|
||||
+ ti.set_last_error(MT_MERR_MAKE_INTERNODE_USE_RESERVED);
|
||||
+ nn = internode_type::make(height + 1, ti, preallocated_internodes[cur_cache_index++]);
|
||||
}
|
||||
|
||||
- if (cur_cache_index == reserved_nodes) {
|
||||
- // Should never happen with pre-allocated internodes (we should have enough reserved nodes). bad flow is not handled
|
||||
- ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_EMPTY_PRE_ALLOC_NOT_EXPECTED);
|
||||
+ if (!nn) {
|
||||
+ // Should never happen with pre-allocated internodes. bad flow is not handled
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_NOT_EXPECTED);
|
||||
+ masstree_invariant(false);
|
||||
}
|
||||
+
|
||||
nn->child_[0] = n;
|
||||
nn->assign(0, xikey[sense], child);
|
||||
nn->nkeys_ = 1;
|
||||
@@ -309,15 +302,16 @@ bool tcursor<P>::make_split(threadinfo& ti)
|
||||
} else {
|
||||
if (p->size() >= p->width) {
|
||||
masstree_invariant(preallocated_internodes[cur_cache_index]);
|
||||
- next_child = internode_type::make(height + 1, ti, preallocated_internodes[cur_cache_index++]);
|
||||
+ next_child = internode_type::make(height + 1, ti, nullptr);
|
||||
if (!next_child) {
|
||||
- // Should never happen with pre-allocated internodes. bad flow is not handled
|
||||
- ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_NOT_EXPECTED_2);
|
||||
+ ti.set_last_error(MT_MERR_MAKE_INTERNODE_USE_RESERVED_2);
|
||||
+ next_child = internode_type::make(height + 1, ti, preallocated_internodes[cur_cache_index++]);
|
||||
}
|
||||
|
||||
- if (cur_cache_index == reserved_nodes) {
|
||||
- // Should never happen with pre-allocated internodes (we should have enough reserved nodes). bad flow is not handled
|
||||
- ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_EMPTY_PRE_ALLOC_NOT_EXPECTED_2);
|
||||
+ if (!next_child) {
|
||||
+ // Should never happen with pre-allocated internodes. bad flow is not handled
|
||||
+ ti.set_last_error(MT_MERR_MAKE_SPLIT_INTERNODE_ALLOC_NOT_EXPECTED_2);
|
||||
+ masstree_invariant(false);
|
||||
}
|
||||
|
||||
next_child->assign_version(*p);
|
||||
--
|
||||
2.17.1
|
||||
|
@ -1,18 +1,18 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) Huawei Technologies Co., Ltd. 2010-2018. All rights reserved.
|
||||
# Copyright (c) Huawei Technologies Co., Ltd. 2010-2023. All rights reserved.
|
||||
# description: the script that make install masstree
|
||||
# date: 2020-12-16
|
||||
# version: 1.0
|
||||
# history:
|
||||
# 2020-12-16 first version
|
||||
# 2023-08-29 change Masstree base version to v1.0.1 and squash all changes into single patch file
|
||||
|
||||
set -e
|
||||
# change compress type
|
||||
|
||||
CUR_DIR=$(pwd)
|
||||
|
||||
MASSTREE_PACKAGE=masstree-beta-0.9.0.tar.gz
|
||||
MASSTREE_PATCH=0001-masstree.patch
|
||||
MASSTREE_PACKAGE=masstree-beta-1.0.1.tar.gz
|
||||
MASSTREE_SOURCES_TMP_DIR=tmp
|
||||
LOCAL_DIR=$(dirname "${LOCAL_PATH}")
|
||||
MASSTREE_MEGRED_SOURCES_DIR=masstree-beta
|
||||
@ -24,10 +24,7 @@ mkdir ${MASSTREE_MEGRED_SOURCES_DIR}
|
||||
tar -zxf $MASSTREE_PACKAGE -C $MASSTREE_MEGRED_SOURCES_DIR --strip-components 1
|
||||
|
||||
cd $MASSTREE_MEGRED_SOURCES_DIR
|
||||
patch -p1 < ../$MASSTREE_PATCH
|
||||
patch -p1 < ../0002-masstree_oom_fix.patch
|
||||
patch -p1 < ../0003-masstree_code_cleanup.patch
|
||||
patch -p1 < ../0004-masstree_reserved_nodes_fix.patch
|
||||
patch -p1 < ../0001-Masstree-v1.0.1-MOT.patch
|
||||
sed -i "s/LDFLAGS =/LDFLAGS = -fstack-protector-all -z,now/g" Makefile
|
||||
sed -i "s/\$(CXX) -shared/\$(CXX) -fstack-protector-all -Wl,-z,relro,-z,now -shared/g" Makefile
|
||||
|
||||
@ -41,4 +38,4 @@ mkdir -p ${INSTALL_DIR}/comm/include
|
||||
mkdir -p ${INSTALL_DIR}/comm/lib
|
||||
cp ${MASSTREE_MEGRED_SOURCES_DIR}/*.h* ${INSTALL_DIR}/comm/include
|
||||
cp ${MASSTREE_MEGRED_SOURCES_DIR}/libmasstree.so ${INSTALL_DIR}/comm/lib
|
||||
|
||||
rm -rf ${MASSTREE_MEGRED_SOURCES_DIR}
|
||||
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
dependency/masstree/masstree-beta-1.0.1.tar.gz
Normal file
BIN
dependency/masstree/masstree-beta-1.0.1.tar.gz
Normal file
Binary file not shown.
@ -2,4 +2,4 @@
|
||||
|
||||
1. Usage
|
||||
|
||||
sh build.sh to fetch masstree-beta-0.9.0
|
||||
sh build.sh to fetch masstree-beta-1.0.1
|
||||
|
161
dependency/nghttp2/CVE-2024-28182.patch
Normal file
161
dependency/nghttp2/CVE-2024-28182.patch
Normal file
@ -0,0 +1,161 @@
|
||||
diff -Naur a/doc/Makefile.am b/doc/Makefile.am
|
||||
--- a/doc/Makefile.am 2024-04-15 19:33:38.344785283 +0800
|
||||
+++ b/doc/Makefile.am 2024-04-15 20:15:35.145757969 +0800
|
||||
@@ -68,6 +68,7 @@
|
||||
nghttp2_option_set_no_recv_client_magic.rst \
|
||||
nghttp2_option_set_peer_max_concurrent_streams.rst \
|
||||
nghttp2_option_set_user_recv_extension_type.rst \
|
||||
+ nghttp2_option_set_max_continuations.rst \
|
||||
nghttp2_option_set_max_outbound_ack.rst \
|
||||
nghttp2_option_set_max_settings.rst \
|
||||
nghttp2_option_set_stream_reset_rate_limit.rst \
|
||||
diff -Naur a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h
|
||||
--- a/lib/includes/nghttp2/nghttp2.h 2024-04-15 19:33:38.348785336 +0800
|
||||
+++ b/lib/includes/nghttp2/nghttp2.h 2024-04-15 20:15:35.149758022 +0800
|
||||
@@ -440,7 +440,12 @@
|
||||
* exhaustion on server side to send these frames forever and does
|
||||
* not read network.
|
||||
*/
|
||||
- NGHTTP2_ERR_FLOODED = -904
|
||||
+ NGHTTP2_ERR_FLOODED = -904,
|
||||
+ /**
|
||||
+ * When a local endpoint receives too many CONTINUATION frames
|
||||
+ * following a HEADER frame.
|
||||
+ */
|
||||
+ NGHTTP2_ERR_TOO_MANY_CONTINUATIONS = -905,
|
||||
} nghttp2_error;
|
||||
|
||||
/**
|
||||
@@ -2738,6 +2743,17 @@
|
||||
|
||||
/**
|
||||
* @function
|
||||
+ *
|
||||
+ * This function sets the maximum number of CONTINUATION frames
|
||||
+ * following an incoming HEADER frame. If more than those frames are
|
||||
+ * received, the remote endpoint is considered to be misbehaving and
|
||||
+ * session will be closed. The default value is 8.
|
||||
+ */
|
||||
+NGHTTP2_EXTERN void nghttp2_option_set_max_continuations(nghttp2_option *option,
|
||||
+ size_t val);
|
||||
+
|
||||
+/**
|
||||
+ * @function
|
||||
*
|
||||
* Initializes |*session_ptr| for client use. The all members of
|
||||
* |callbacks| are copied to |*session_ptr|. Therefore |*session_ptr|
|
||||
diff -Naur a/lib/nghttp2_helper.c b/lib/nghttp2_helper.c
|
||||
--- a/lib/nghttp2_helper.c 2024-04-15 19:33:38.352785388 +0800
|
||||
+++ b/lib/nghttp2_helper.c 2024-04-15 20:15:35.149758022 +0800
|
||||
@@ -336,6 +336,8 @@
|
||||
"closed";
|
||||
case NGHTTP2_ERR_TOO_MANY_SETTINGS:
|
||||
return "SETTINGS frame contained more than the maximum allowed entries";
|
||||
+ case NGHTTP2_ERR_TOO_MANY_CONTINUATIONS:
|
||||
+ return "Too many CONTINUATION frames following a HEADER frame";
|
||||
default:
|
||||
return "Unknown error code";
|
||||
}
|
||||
diff -Naur a/lib/nghttp2_option.c b/lib/nghttp2_option.c
|
||||
--- a/lib/nghttp2_option.c 2024-04-15 19:33:38.348785336 +0800
|
||||
+++ b/lib/nghttp2_option.c 2024-04-15 20:15:35.149758022 +0800
|
||||
@@ -133,3 +133,8 @@
|
||||
option->stream_reset_burst = burst;
|
||||
option->stream_reset_rate = rate;
|
||||
}
|
||||
+
|
||||
+void nghttp2_option_set_max_continuations(nghttp2_option *option, size_t val) {
|
||||
+ option->opt_set_mask |= NGHTTP2_OPT_MAX_CONTINUATIONS;
|
||||
+ option->max_continuations = val;
|
||||
+}
|
||||
diff -Naur a/lib/nghttp2_option.h b/lib/nghttp2_option.h
|
||||
--- a/lib/nghttp2_option.h 2024-04-15 19:33:38.352785388 +0800
|
||||
+++ b/lib/nghttp2_option.h 2024-04-15 20:15:35.153758074 +0800
|
||||
@@ -69,6 +69,7 @@
|
||||
NGHTTP2_OPT_MAX_OUTBOUND_ACK = 1 << 11,
|
||||
NGHTTP2_OPT_MAX_SETTINGS = 1 << 12,
|
||||
NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT = 1 << 15,
|
||||
+ NGHTTP2_OPT_MAX_CONTINUATIONS = 1 << 16,
|
||||
} nghttp2_option_flag;
|
||||
|
||||
/**
|
||||
@@ -97,6 +98,10 @@
|
||||
*/
|
||||
size_t max_settings;
|
||||
/**
|
||||
+ * NGHTTP2_OPT_MAX_CONTINUATIONS
|
||||
+ */
|
||||
+ size_t max_continuations;
|
||||
+ /**
|
||||
* Bitwise OR of nghttp2_option_flag to determine that which fields
|
||||
* are specified.
|
||||
*/
|
||||
diff -Naur a/lib/nghttp2_session.c b/lib/nghttp2_session.c
|
||||
--- a/lib/nghttp2_session.c 2024-04-15 19:33:38.352785388 +0800
|
||||
+++ b/lib/nghttp2_session.c 2024-04-15 20:15:35.153758074 +0800
|
||||
@@ -464,6 +464,7 @@
|
||||
(*session_ptr)->max_send_header_block_length = NGHTTP2_MAX_HEADERSLEN;
|
||||
(*session_ptr)->max_outbound_ack = NGHTTP2_DEFAULT_MAX_OBQ_FLOOD_ITEM;
|
||||
(*session_ptr)->max_settings = NGHTTP2_DEFAULT_MAX_SETTINGS;
|
||||
+ (*session_ptr)->max_continuations = NGHTTP2_DEFAULT_MAX_CONTINUATIONS;
|
||||
|
||||
if (option) {
|
||||
if ((option->opt_set_mask & NGHTTP2_OPT_NO_AUTO_WINDOW_UPDATE) &&
|
||||
@@ -538,6 +539,10 @@
|
||||
option->stream_reset_burst,
|
||||
option->stream_reset_rate);
|
||||
}
|
||||
+
|
||||
+ if (option->opt_set_mask & NGHTTP2_OPT_MAX_CONTINUATIONS) {
|
||||
+ (*session_ptr)->max_continuations = option->max_continuations;
|
||||
+ }
|
||||
}
|
||||
|
||||
rv = nghttp2_hd_deflate_init2(&(*session_ptr)->hd_deflater,
|
||||
@@ -6310,6 +6315,8 @@
|
||||
}
|
||||
}
|
||||
session_inbound_frame_reset(session);
|
||||
+
|
||||
+ session->num_continuations = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -6430,6 +6437,10 @@
|
||||
fprintf(stderr, "recv: [IB_IGN_CONTINUATION]\n");
|
||||
}
|
||||
#endif /* DEBUGBUILD */
|
||||
+
|
||||
+ if (++session->num_continuations > session->max_continuations) {
|
||||
+ return NGHTTP2_ERR_TOO_MANY_CONTINUATIONS;
|
||||
+ }
|
||||
|
||||
readlen = inbound_frame_buf_read(iframe, in, last);
|
||||
in += readlen;
|
||||
diff -Naur a/lib/nghttp2_session.h b/lib/nghttp2_session.h
|
||||
--- a/lib/nghttp2_session.h 2024-04-15 19:33:38.352785388 +0800
|
||||
+++ b/lib/nghttp2_session.h 2024-04-15 20:15:35.153758074 +0800
|
||||
@@ -107,6 +107,10 @@
|
||||
#define NGHTTP2_DEFAULT_STREAM_RESET_BURST 1000
|
||||
#define NGHTTP2_DEFAULT_STREAM_RESET_RATE 33
|
||||
|
||||
+/* The default max number of CONTINUATION frames following an incoming
|
||||
+ HEADER frame. */
|
||||
+#define NGHTTP2_DEFAULT_MAX_CONTINUATIONS 8
|
||||
+
|
||||
/* Internal state when receiving incoming frame */
|
||||
typedef enum {
|
||||
/* Receiving frame header */
|
||||
@@ -279,6 +283,12 @@
|
||||
size_t max_send_header_block_length;
|
||||
/* The maximum number of settings accepted per SETTINGS frame. */
|
||||
size_t max_settings;
|
||||
+ /* The maximum number of CONTINUATION frames following an incoming
|
||||
+ HEADER frame. */
|
||||
+ size_t max_continuations;
|
||||
+ /* The number of CONTINUATION frames following an incoming HEADER
|
||||
+ frame. This variable is reset when END_HEADERS flag is seen. */
|
||||
+ size_t num_continuations;
|
||||
/* Next Stream ID. Made unsigned int to detect >= (1 << 31). */
|
||||
uint32_t next_stream_id;
|
||||
/* The last stream ID this session initiated. For client session,
|
@ -26,6 +26,7 @@ mkdir -p ${build_dir}
|
||||
cd $nghttp2_dir
|
||||
patch -p1 < ../cve-2023-35945.patch
|
||||
patch -p1 < ../CVE-2023-44487.patch
|
||||
patch -p1 < ../CVE-2024-28182.patch
|
||||
cmake -DCMAKE_INSTALL_PREFIX=$build_dir -D CMAKE_PROJECT_INCLUDE=${current_dir}/project_include.cmake
|
||||
|
||||
make install -sj
|
||||
|
Binary file not shown.
BIN
dependency/numactl/numactl-2.0.16.tar.gz
Normal file
BIN
dependency/numactl/numactl-2.0.16.tar.gz
Normal file
Binary file not shown.
@ -0,0 +1,108 @@
|
||||
From 400e9ffc906d66318e4f9364494809d5a519c718 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Yang <yang.yang@baishancloud.com>
|
||||
Date: Wed, 13 Mar 2019 17:22:31 +0800
|
||||
Subject: [PATCH 06/15] Add documents for SM2 cert verification
|
||||
|
||||
This follows #8321 which added the SM2 certificate verification feature.
|
||||
This commit adds the related docs - the newly added 2 APIs and options
|
||||
in apps/verify.
|
||||
|
||||
Reviewed-by: Paul Dale <paul.dale@oracle.com>
|
||||
(Merged from https://github.com/openssl/openssl/pull/8465)
|
||||
---
|
||||
doc/man1/verify.pod | 14 ++++++++++++
|
||||
doc/man3/X509_get0_sm2_id.pod | 43 +++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 57 insertions(+)
|
||||
create mode 100644 doc/man3/X509_get0_sm2_id.pod
|
||||
|
||||
diff --git a/doc/man1/verify.pod b/doc/man1/verify.pod
|
||||
index da2b702..a6b6b2b 100644
|
||||
--- a/doc/man1/verify.pod
|
||||
+++ b/doc/man1/verify.pod
|
||||
@@ -50,6 +50,8 @@ B<openssl> B<verify>
|
||||
[B<-verify_name name>]
|
||||
[B<-x509_strict>]
|
||||
[B<-show_chain>]
|
||||
+[B<-sm2-id string>]
|
||||
+[B<-sm2-hex-id hex-string>]
|
||||
[B<->]
|
||||
[certificates]
|
||||
|
||||
@@ -319,6 +321,16 @@ Display information about the certificate chain that has been built (if
|
||||
successful). Certificates in the chain that came from the untrusted list will be
|
||||
flagged as "untrusted".
|
||||
|
||||
+=item B<-sm2-id>
|
||||
+
|
||||
+Specify the ID string to use when verifying an SM2 certificate. The ID string is
|
||||
+required by the SM2 signature algorithm for signing and verification.
|
||||
+
|
||||
+=item B<-sm2-hex-id>
|
||||
+
|
||||
+Specify a binary ID string to use when signing or verifying using an SM2
|
||||
+certificate. The argument for this option is string of hexadecimal digits.
|
||||
+
|
||||
=item B<->
|
||||
|
||||
Indicates the last option. All arguments following this are assumed to be
|
||||
@@ -774,6 +786,8 @@ The B<-show_chain> option was added in OpenSSL 1.1.0.
|
||||
The B<-issuer_checks> option is deprecated as of OpenSSL 1.1.0 and
|
||||
is silently ignored.
|
||||
|
||||
+The B<-sm2-id> and B<-sm2-hex-id> options were added in OpenSSL 3.0.0.
|
||||
+
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
diff --git a/doc/man3/X509_get0_sm2_id.pod b/doc/man3/X509_get0_sm2_id.pod
|
||||
new file mode 100644
|
||||
index 0000000..84da71e
|
||||
--- /dev/null
|
||||
+++ b/doc/man3/X509_get0_sm2_id.pod
|
||||
@@ -0,0 +1,43 @@
|
||||
+=pod
|
||||
+
|
||||
+=head1 NAME
|
||||
+
|
||||
+X509_get0_sm2_id, X509_set_sm2_id - get or set SM2 ID for certificate operations
|
||||
+
|
||||
+=head1 SYNOPSIS
|
||||
+
|
||||
+ #include <openssl/x509.h>
|
||||
+
|
||||
+ ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x);
|
||||
+ void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||
+
|
||||
+=head1 DESCRIPTION
|
||||
+
|
||||
+X509_get0_sm2_id() gets the ID value of an SM2 certificate B<x> by returning an
|
||||
+B<ASN1_OCTET_STRING> object which should not be freed by the caller.
|
||||
+X509_set_sm2_id() sets the B<sm2_id> value to an SM2 certificate B<x>.
|
||||
+
|
||||
+=head1 NOTES
|
||||
+
|
||||
+SM2 signature algorithm requires an ID value when generating and verifying a
|
||||
+signature. The functions described in this manual provide the user with the
|
||||
+ability to set and retrieve the SM2 ID value.
|
||||
+
|
||||
+=head1 RETURN VALUES
|
||||
+
|
||||
+X509_set_sm2_id() does not return a value.
|
||||
+
|
||||
+=head1 SEE ALSO
|
||||
+
|
||||
+L<X509_verify(3)>, L<SM2(7)>
|
||||
+
|
||||
+=head1 COPYRIGHT
|
||||
+
|
||||
+Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+
|
||||
+Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
+this file except in compliance with the License. You can obtain a copy
|
||||
+in the file LICENSE in the source distribution or at
|
||||
+L<https://www.openssl.org/source/license.html>.
|
||||
+
|
||||
+=cut
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,127 @@
|
||||
From c08251384c0405c151a90b315b8f333c38c74eb2 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Yang <yang.yang@baishancloud.com>
|
||||
Date: Wed, 13 Mar 2019 16:54:11 +0800
|
||||
Subject: [PATCH 05/15] Add test cases for SM2 cert verification
|
||||
|
||||
This follows #8321 which added the SM2 certificate verification feature.
|
||||
This commit adds some test cases for #8321.
|
||||
|
||||
Reviewed-by: Paul Dale <paul.dale@oracle.com>
|
||||
(Merged from https://github.com/openssl/openssl/pull/8465)
|
||||
---
|
||||
test/certs/sm2-ca-cert.pem | 14 +++++++++++++
|
||||
test/certs/{sm2.crt => sm2.pem} | 0
|
||||
test/recipes/20-test_pkeyutl.t | 37 +++++++++++++--------------------
|
||||
test/recipes/25-test_verify.t | 14 ++++++++++++-
|
||||
4 files changed, 42 insertions(+), 23 deletions(-)
|
||||
create mode 100644 test/certs/sm2-ca-cert.pem
|
||||
rename test/certs/{sm2.crt => sm2.pem} (100%)
|
||||
|
||||
diff --git a/test/certs/sm2-ca-cert.pem b/test/certs/sm2-ca-cert.pem
|
||||
new file mode 100644
|
||||
index 0000000..5677ac6
|
||||
--- /dev/null
|
||||
+++ b/test/certs/sm2-ca-cert.pem
|
||||
@@ -0,0 +1,14 @@
|
||||
+-----BEGIN CERTIFICATE-----
|
||||
+MIICJDCCAcqgAwIBAgIJAOlkpDpSrmVbMAoGCCqBHM9VAYN1MGgxCzAJBgNVBAYT
|
||||
+AkNOMQswCQYDVQQIDAJMTjERMA8GA1UEBwwIU2hlbnlhbmcxETAPBgNVBAoMCFRl
|
||||
+c3QgT3JnMRAwDgYDVQQLDAdUZXN0IE9VMRQwEgYDVQQDDAtUZXN0IFNNMiBDQTAe
|
||||
+Fw0xOTAyMTkwNzA1NDhaFw0yMzAzMzAwNzA1NDhaMGgxCzAJBgNVBAYTAkNOMQsw
|
||||
+CQYDVQQIDAJMTjERMA8GA1UEBwwIU2hlbnlhbmcxETAPBgNVBAoMCFRlc3QgT3Jn
|
||||
+MRAwDgYDVQQLDAdUZXN0IE9VMRQwEgYDVQQDDAtUZXN0IFNNMiBDQTBZMBMGByqG
|
||||
+SM49AgEGCCqBHM9VAYItA0IABHRYnqErofBdXPptvvO7+BSVJxcpHuTGnZ+UPrbU
|
||||
+5kVEUMaUnNOeMJZl/vRGimZCm/AkReJmRfnb15ESHR+ssp6jXTBbMB0GA1UdDgQW
|
||||
+BBTFjcWu/zJgSZ5SKUlU5Vx4/0W5dDAfBgNVHSMEGDAWgBTFjcWu/zJgSZ5SKUlU
|
||||
+5Vx4/0W5dDAMBgNVHRMEBTADAQH/MAsGA1UdDwQEAwIBBjAKBggqgRzPVQGDdQNI
|
||||
+ADBFAiEAs6byi1nSQtFELOw/2tQIv5AEsZFR5MJ/oB2ztXzs2LYCIEfIw4xlUH6X
|
||||
+YFhs4RnIa0K9Ng1ebsGPrifYkudwBIk3
|
||||
+-----END CERTIFICATE-----
|
||||
diff --git a/test/certs/sm2.crt b/test/certs/sm2.pem
|
||||
similarity index 100%
|
||||
rename from test/certs/sm2.crt
|
||||
rename to test/certs/sm2.pem
|
||||
diff --git a/test/recipes/20-test_pkeyutl.t b/test/recipes/20-test_pkeyutl.t
|
||||
index 1457530..a36d41e 100644
|
||||
--- a/test/recipes/20-test_pkeyutl.t
|
||||
+++ b/test/recipes/20-test_pkeyutl.t
|
||||
@@ -17,32 +17,25 @@ setup("test_pkeyutl");
|
||||
|
||||
plan tests => 2;
|
||||
|
||||
-sub sign
|
||||
-{
|
||||
- # Utilize the sm2.crt as the TBS file
|
||||
- return run(app(([ 'openssl', 'pkeyutl', '-sign',
|
||||
- '-in', srctop_file('test', 'certs', 'sm2.crt'),
|
||||
- '-inkey', srctop_file('test', 'certs', 'sm2.key'),
|
||||
- '-out', 'signature.sm2', '-rawin',
|
||||
- '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
|
||||
-}
|
||||
-
|
||||
-sub verify
|
||||
-{
|
||||
- # Utilize the sm2.crt as the TBS file
|
||||
- return run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
|
||||
- '-in', srctop_file('test', 'certs', 'sm2.crt'),
|
||||
- '-inkey', srctop_file('test', 'certs', 'sm2.crt'),
|
||||
- '-sigfile', 'signature.sm2', '-rawin',
|
||||
- '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
|
||||
-}
|
||||
+# For the tests below we use the cert itself as the TBS file
|
||||
|
||||
SKIP: {
|
||||
skip "Skipping tests that require EC, SM2 or SM3", 2
|
||||
if disabled("ec") || disabled("sm2") || disabled("sm3");
|
||||
|
||||
- ok(sign, "Sign a piece of data using SM2");
|
||||
- ok(verify, "Verify an SM2 signature against a piece of data");
|
||||
+ # SM2
|
||||
+ ok(run(app(([ 'openssl', 'pkeyutl', '-sign',
|
||||
+ '-in', srctop_file('test', 'certs', 'sm2.pem'),
|
||||
+ '-inkey', srctop_file('test', 'certs', 'sm2.key'),
|
||||
+ '-out', 'signature.dat', '-rawin',
|
||||
+ '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid']))),
|
||||
+ "Sign a piece of data using SM2");
|
||||
+ ok(run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
|
||||
+ '-in', srctop_file('test', 'certs', 'sm2.pem'),
|
||||
+ '-inkey', srctop_file('test', 'certs', 'sm2.pem'),
|
||||
+ '-sigfile', 'signature.dat', '-rawin',
|
||||
+ '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid']))),
|
||||
+ "Verify an SM2 signature against a piece of data");
|
||||
}
|
||||
|
||||
-unlink 'signature.sm2';
|
||||
+unlink 'signature.dat';
|
||||
diff --git a/test/recipes/25-test_verify.t b/test/recipes/25-test_verify.t
|
||||
index ffa48ed..b340833 100644
|
||||
--- a/test/recipes/25-test_verify.t
|
||||
+++ b/test/recipes/25-test_verify.t
|
||||
@@ -27,7 +27,7 @@ sub verify {
|
||||
run(app([@args]));
|
||||
}
|
||||
|
||||
-plan tests => 146;
|
||||
+plan tests => 148;
|
||||
|
||||
# Canonical success
|
||||
ok(verify("ee-cert", "sslserver", ["root-cert"], ["ca-cert"]),
|
||||
@@ -409,3 +409,15 @@ SKIP: {
|
||||
"ED25519 signature");
|
||||
|
||||
}
|
||||
+
|
||||
+SKIP: {
|
||||
+ skip "SM2 is not supported by this OpenSSL build", 1
|
||||
+ if disabled("sm2");
|
||||
+
|
||||
+ # Test '-sm2-id' and '-sm2-hex-id' option
|
||||
+ ok(verify("sm2", "any", ["sm2-ca-cert"], [], "-sm2-id", "1234567812345678"),
|
||||
+ "SM2 ID test");
|
||||
+ ok(verify("sm2", "any", ["sm2-ca-cert"], [], "-sm2-hex-id",
|
||||
+ "31323334353637383132333435363738"),
|
||||
+ "SM2 hex ID test");
|
||||
+}
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,29 @@
|
||||
From 7e64be50900c4aa8cd040c4e3999540883bdeeb6 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Yang <kaishen.yy@antfin.com>
|
||||
Date: Thu, 26 Sep 2019 10:57:23 +0800
|
||||
Subject: [PATCH 13/15] Fix a document description in apps/req
|
||||
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/9958)
|
||||
---
|
||||
doc/man1/req.pod | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/doc/man1/req.pod b/doc/man1/req.pod
|
||||
index 7b00bad..e117ec6 100644
|
||||
--- a/doc/man1/req.pod
|
||||
+++ b/doc/man1/req.pod
|
||||
@@ -348,8 +348,8 @@ string is required by the SM2 signature algorithm for signing and verification.
|
||||
|
||||
=item B<-sm2-hex-id>
|
||||
|
||||
-Specify a binary ID string to use when signing or verifying using an SM2
|
||||
-certificate. The argument for this option is string of hexadecimal digits.
|
||||
+Specify a binary ID string to use when verifying an SM2 certificate request. The
|
||||
+argument for this option is string of hexadecimal digits.
|
||||
|
||||
=back
|
||||
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,121 @@
|
||||
From a63238684c1d2e15f417f766f44418a8b52ef383 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Yang <kaishen.yy@antfin.com>
|
||||
Date: Sat, 21 Sep 2019 00:32:57 +0800
|
||||
Subject: [PATCH 12/15] Fix a double free issue when signing SM2 cert
|
||||
|
||||
If the SM2 ID value has not been passed correctly when signing an SM2
|
||||
certificate/certificate request, a double free occurs. For instance:
|
||||
|
||||
openssl req -x509 ... -sm2-id 1234567812345678
|
||||
|
||||
The '-sm2-id' should not be used in this scenario, while the '-sigopt' is
|
||||
the correct one to use. Documentation has also been updated to make the
|
||||
options more clear.
|
||||
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/9958)
|
||||
---
|
||||
apps/req.c | 48 ++++++++++++++++++++++++++++++------------------
|
||||
doc/man1/req.pod | 4 ++--
|
||||
2 files changed, 32 insertions(+), 20 deletions(-)
|
||||
|
||||
diff --git a/apps/req.c b/apps/req.c
|
||||
index 96f1edd..95dd0e4 100644
|
||||
--- a/apps/req.c
|
||||
+++ b/apps/req.c
|
||||
@@ -1756,15 +1756,19 @@ int do_X509_sign(X509 *x, EVP_PKEY *pkey, const EVP_MD *md,
|
||||
#endif
|
||||
|
||||
rv = do_sign_init(mctx, pkey, md, sigopts);
|
||||
- if (rv > 0)
|
||||
+ if (rv > 0) {
|
||||
rv = X509_sign_ctx(x, mctx);
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
- /* only in SM2 case we need to free the pctx explicitly */
|
||||
- if (ec_pkey_is_sm2(pkey)) {
|
||||
- pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||
- EVP_PKEY_CTX_free(pctx);
|
||||
- }
|
||||
+ /*
|
||||
+ * only in SM2 case we need to free the pctx explicitly
|
||||
+ * if do_sign_init() fails, pctx is already freed in it
|
||||
+ */
|
||||
+ if (ec_pkey_is_sm2(pkey)) {
|
||||
+ pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||
+ EVP_PKEY_CTX_free(pctx);
|
||||
+ }
|
||||
#endif
|
||||
+ }
|
||||
EVP_MD_CTX_free(mctx);
|
||||
return rv > 0 ? 1 : 0;
|
||||
}
|
||||
@@ -1779,15 +1783,19 @@ int do_X509_REQ_sign(X509_REQ *x, EVP_PKEY *pkey, const EVP_MD *md,
|
||||
#endif
|
||||
|
||||
rv = do_sign_init(mctx, pkey, md, sigopts);
|
||||
- if (rv > 0)
|
||||
+ if (rv > 0) {
|
||||
rv = X509_REQ_sign_ctx(x, mctx);
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
- /* only in SM2 case we need to free the pctx explicitly */
|
||||
- if (ec_pkey_is_sm2(pkey)) {
|
||||
- pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||
- EVP_PKEY_CTX_free(pctx);
|
||||
- }
|
||||
+ /*
|
||||
+ * only in SM2 case we need to free the pctx explicitly
|
||||
+ * if do_sign_init() fails, pctx is already freed in it
|
||||
+ */
|
||||
+ if (ec_pkey_is_sm2(pkey)) {
|
||||
+ pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||
+ EVP_PKEY_CTX_free(pctx);
|
||||
+ }
|
||||
#endif
|
||||
+ }
|
||||
EVP_MD_CTX_free(mctx);
|
||||
return rv > 0 ? 1 : 0;
|
||||
}
|
||||
@@ -1802,15 +1810,19 @@ int do_X509_CRL_sign(X509_CRL *x, EVP_PKEY *pkey, const EVP_MD *md,
|
||||
#endif
|
||||
|
||||
rv = do_sign_init(mctx, pkey, md, sigopts);
|
||||
- if (rv > 0)
|
||||
+ if (rv > 0) {
|
||||
rv = X509_CRL_sign_ctx(x, mctx);
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
- /* only in SM2 case we need to free the pctx explicitly */
|
||||
- if (ec_pkey_is_sm2(pkey)) {
|
||||
- pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||
- EVP_PKEY_CTX_free(pctx);
|
||||
- }
|
||||
+ /*
|
||||
+ * only in SM2 case we need to free the pctx explicitly
|
||||
+ * if do_sign_init() fails, no need to double free pctx
|
||||
+ */
|
||||
+ if (ec_pkey_is_sm2(pkey)) {
|
||||
+ pctx = EVP_MD_CTX_pkey_ctx(mctx);
|
||||
+ EVP_PKEY_CTX_free(pctx);
|
||||
+ }
|
||||
#endif
|
||||
+ }
|
||||
EVP_MD_CTX_free(mctx);
|
||||
return rv > 0 ? 1 : 0;
|
||||
}
|
||||
diff --git a/doc/man1/req.pod b/doc/man1/req.pod
|
||||
index 3b9fcc3..7b00bad 100644
|
||||
--- a/doc/man1/req.pod
|
||||
+++ b/doc/man1/req.pod
|
||||
@@ -343,8 +343,8 @@ for key generation operations.
|
||||
|
||||
=item B<-sm2-id>
|
||||
|
||||
-Specify the ID string to use when verifying an SM2 certificate. The ID string is
|
||||
-required by the SM2 signature algorithm for signing and verification.
|
||||
+Specify the ID string to use when verifying an SM2 certificate request. The ID
|
||||
+string is required by the SM2 signature algorithm for signing and verification.
|
||||
|
||||
=item B<-sm2-hex-id>
|
||||
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,43 @@
|
||||
From 1c243548ef736329b08344ad9191803e5a93ec17 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Yang <yang.yang@baishancloud.com>
|
||||
Date: Wed, 13 Mar 2019 18:04:05 +0800
|
||||
Subject: [PATCH 07/15] Fix a memleak in apps/verify
|
||||
|
||||
Reviewed-by: Paul Dale <paul.dale@oracle.com>
|
||||
(Merged from https://github.com/openssl/openssl/pull/8465)
|
||||
---
|
||||
apps/verify.c | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/apps/verify.c b/apps/verify.c
|
||||
index 09b31cf..5052d80 100644
|
||||
--- a/apps/verify.c
|
||||
+++ b/apps/verify.c
|
||||
@@ -80,6 +80,7 @@ int verify_main(int argc, char **argv)
|
||||
OPTION_CHOICE o;
|
||||
unsigned char *sm2_id = NULL;
|
||||
size_t sm2_idlen = 0;
|
||||
+ int sm2_free = 0;
|
||||
|
||||
if ((vpm = X509_VERIFY_PARAM_new()) == NULL)
|
||||
goto end;
|
||||
@@ -174,6 +175,7 @@ int verify_main(int argc, char **argv)
|
||||
break;
|
||||
case OPT_SM2HEXID:
|
||||
/* try to parse the input as hex string first */
|
||||
+ sm2_free = 1;
|
||||
sm2_id = OPENSSL_hexstr2buf(opt_arg(), (long *)&sm2_idlen);
|
||||
if (sm2_id == NULL) {
|
||||
BIO_printf(bio_err, "Invalid hex string input\n");
|
||||
@@ -216,6 +218,8 @@ int verify_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
end:
|
||||
+ if (sm2_free)
|
||||
+ OPENSSL_free(sm2_id);
|
||||
X509_VERIFY_PARAM_free(vpm);
|
||||
X509_STORE_free(store);
|
||||
sk_X509_pop_free(untrusted, X509_free);
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,67 @@
|
||||
From 380cf570be1ded495141e16ceab7afb7f7c57ab7 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Thu, 28 Feb 2019 13:47:26 +0000
|
||||
Subject: [PATCH 02/15] Fix no-ec, no-sm2 and no-sm3
|
||||
|
||||
Reviewed-by: Richard Levitte <levitte@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/8372)
|
||||
---
|
||||
apps/pkeyutl.c | 11 +++++++----
|
||||
test/recipes/20-test_pkeyutl.t | 9 +++++++--
|
||||
2 files changed, 14 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c
|
||||
index bca0464..1d3d57b 100644
|
||||
--- a/apps/pkeyutl.c
|
||||
+++ b/apps/pkeyutl.c
|
||||
@@ -473,14 +473,16 @@ static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||
}
|
||||
ctx = EVP_PKEY_CTX_new_id(kdfnid, impl);
|
||||
} else {
|
||||
- EC_KEY *eckey = NULL;
|
||||
- const EC_GROUP *group = NULL;
|
||||
- int nid;
|
||||
-
|
||||
if (pkey == NULL)
|
||||
goto end;
|
||||
+
|
||||
+#ifndef OPENSSL_NO_EC
|
||||
/* SM2 needs a special treatment */
|
||||
if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
|
||||
+ EC_KEY *eckey = NULL;
|
||||
+ const EC_GROUP *group = NULL;
|
||||
+ int nid;
|
||||
+
|
||||
if ((eckey = EVP_PKEY_get0_EC_KEY(pkey)) == NULL
|
||||
|| (group = EC_KEY_get0_group(eckey)) == NULL
|
||||
|| (nid = EC_GROUP_get_curve_name(group)) == 0)
|
||||
@@ -488,6 +490,7 @@ static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||
if (nid == NID_sm2)
|
||||
EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
|
||||
}
|
||||
+#endif
|
||||
*pkeysize = EVP_PKEY_size(pkey);
|
||||
ctx = EVP_PKEY_CTX_new(pkey, impl);
|
||||
if (ppkey != NULL)
|
||||
diff --git a/test/recipes/20-test_pkeyutl.t b/test/recipes/20-test_pkeyutl.t
|
||||
index a051138..1457530 100644
|
||||
--- a/test/recipes/20-test_pkeyutl.t
|
||||
+++ b/test/recipes/20-test_pkeyutl.t
|
||||
@@ -37,7 +37,12 @@ sub verify
|
||||
'-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
|
||||
}
|
||||
|
||||
-ok(sign, "Sign a piece of data using SM2");
|
||||
-ok(verify, "Verify an SM2 signature against a piece of data");
|
||||
+SKIP: {
|
||||
+ skip "Skipping tests that require EC, SM2 or SM3", 2
|
||||
+ if disabled("ec") || disabled("sm2") || disabled("sm3");
|
||||
+
|
||||
+ ok(sign, "Sign a piece of data using SM2");
|
||||
+ ok(verify, "Verify an SM2 signature against a piece of data");
|
||||
+}
|
||||
|
||||
unlink 'signature.sm2';
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,44 @@
|
||||
From 908570d02b683195ddfdc8e8c324638bfaa0d2c2 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Thu, 14 Mar 2019 11:14:38 +0000
|
||||
Subject: [PATCH 04/15] Guard some SM2 functions with OPENSSL_NO_SM2
|
||||
|
||||
Fixes the no-ec build
|
||||
|
||||
Reviewed-by: Richard Levitte <levitte@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/8481)
|
||||
---
|
||||
include/openssl/x509.h | 2 ++
|
||||
util/libcrypto.num | 4 ++--
|
||||
2 files changed, 4 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/include/openssl/x509.h b/include/openssl/x509.h
|
||||
index 5f17057..5c88251 100644
|
||||
--- a/include/openssl/x509.h
|
||||
+++ b/include/openssl/x509.h
|
||||
@@ -573,8 +573,10 @@ void X509_get0_signature(const ASN1_BIT_STRING **psig,
|
||||
const X509_ALGOR **palg, const X509 *x);
|
||||
int X509_get_signature_nid(const X509 *x);
|
||||
|
||||
+# ifndef OPENSSL_NO_SM2
|
||||
void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||
ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x);
|
||||
+# endif
|
||||
|
||||
int X509_trusted(const X509 *x);
|
||||
int X509_alias_set1(X509 *x, const unsigned char *name, int len);
|
||||
diff --git a/util/libcrypto.num b/util/libcrypto.num
|
||||
index 8635ac4..233d1c7 100644
|
||||
--- a/util/libcrypto.num
|
||||
+++ b/util/libcrypto.num
|
||||
@@ -4626,5 +4626,5 @@ FIPS_drbg_get_strength 6379 1_1_0g EXIST::FUNCTION:
|
||||
FIPS_rand_strength 6380 1_1_0g EXIST::FUNCTION:
|
||||
FIPS_drbg_get_blocklength 6381 1_1_0g EXIST::FUNCTION:
|
||||
FIPS_drbg_init 6382 1_1_0g EXIST::FUNCTION:
|
||||
-X509_set_sm2_id 6383 1_1_1m EXIST::FUNCTION:
|
||||
-X509_get0_sm2_id 6384 1_1_1m EXIST::FUNCTION:
|
||||
+X509_set_sm2_id 6383 1_1_1m EXIST::FUNCTION:SM2
|
||||
+X509_get0_sm2_id 6384 1_1_1m EXIST::FUNCTION:SM2
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,320 @@
|
||||
From 0717cc33d72b011cce4f53661c58d628b684275c Mon Sep 17 00:00:00 2001
|
||||
From: Paul Yang <yang.yang@baishancloud.com>
|
||||
Date: Mon, 1 Apr 2019 10:21:53 +0900
|
||||
Subject: [PATCH 09/15] Make X509_set_sm2_id consistent with other setters
|
||||
|
||||
This commit makes the X509_set_sm2_id to 'set0' behaviour, which means
|
||||
the memory management is passed to X509 and user doesn't need to free
|
||||
the sm2_id parameter later. API name also changes to X509_set0_sm2_id.
|
||||
|
||||
Document and test case are also updated.
|
||||
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/8626)
|
||||
---
|
||||
apps/verify.c | 40 +++++++++++++++++++-----------
|
||||
crypto/x509/x_all.c | 5 +++-
|
||||
crypto/x509/x_x509.c | 13 +++++++---
|
||||
doc/man3/X509_get0_sm2_id.pod | 12 ++++++---
|
||||
include/crypto/x509.h | 2 +-
|
||||
include/openssl/x509.h | 2 +-
|
||||
test/verify_extra_test.c | 46 +++++++++++++++++++++++++++++++++++
|
||||
util/libcrypto.num | 2 +-
|
||||
8 files changed, 97 insertions(+), 25 deletions(-)
|
||||
|
||||
diff --git a/apps/verify.c b/apps/verify.c
|
||||
index 5052d80..9000567 100644
|
||||
--- a/apps/verify.c
|
||||
+++ b/apps/verify.c
|
||||
@@ -246,27 +246,37 @@ static int check(X509_STORE *ctx, const char *file,
|
||||
|
||||
if (sm2id != NULL) {
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
- ASN1_OCTET_STRING v;
|
||||
+ ASN1_OCTET_STRING *v;
|
||||
|
||||
- v.data = sm2id;
|
||||
- v.length = sm2idlen;
|
||||
+ v = ASN1_OCTET_STRING_new();
|
||||
+ if (v == NULL) {
|
||||
+ BIO_printf(bio_err, "error: SM2 ID allocation failed\n");
|
||||
+ goto end;
|
||||
+ }
|
||||
|
||||
- X509_set_sm2_id(x, &v);
|
||||
+ if (!ASN1_OCTET_STRING_set(v, sm2id, sm2idlen)) {
|
||||
+ BIO_printf(bio_err, "error: setting SM2 ID failed\n");
|
||||
+ ASN1_OCTET_STRING_free(v);
|
||||
+ goto end;
|
||||
+ }
|
||||
+
|
||||
+ X509_set0_sm2_id(x, v);
|
||||
#endif
|
||||
}
|
||||
|
||||
csc = X509_STORE_CTX_new();
|
||||
if (csc == NULL) {
|
||||
- printf("error %s: X.509 store context allocation failed\n",
|
||||
- (file == NULL) ? "stdin" : file);
|
||||
+ BIO_printf(bio_err, "error %s: X.509 store context allocation failed\n",
|
||||
+ (file == NULL) ? "stdin" : file);
|
||||
goto end;
|
||||
}
|
||||
|
||||
X509_STORE_set_flags(ctx, vflags);
|
||||
if (!X509_STORE_CTX_init(csc, ctx, x, uchain)) {
|
||||
X509_STORE_CTX_free(csc);
|
||||
- printf("error %s: X.509 store context initialization failed\n",
|
||||
- (file == NULL) ? "stdin" : file);
|
||||
+ BIO_printf(bio_err,
|
||||
+ "error %s: X.509 store context initialization failed\n",
|
||||
+ (file == NULL) ? "stdin" : file);
|
||||
goto end;
|
||||
}
|
||||
if (tchain != NULL)
|
||||
@@ -275,28 +285,30 @@ static int check(X509_STORE *ctx, const char *file,
|
||||
X509_STORE_CTX_set0_crls(csc, crls);
|
||||
i = X509_verify_cert(csc);
|
||||
if (i > 0 && X509_STORE_CTX_get_error(csc) == X509_V_OK) {
|
||||
- printf("%s: OK\n", (file == NULL) ? "stdin" : file);
|
||||
+ BIO_printf(bio_out, "%s: OK\n", (file == NULL) ? "stdin" : file);
|
||||
ret = 1;
|
||||
if (show_chain) {
|
||||
int j;
|
||||
|
||||
chain = X509_STORE_CTX_get1_chain(csc);
|
||||
num_untrusted = X509_STORE_CTX_get_num_untrusted(csc);
|
||||
- printf("Chain:\n");
|
||||
+ BIO_printf(bio_out, "Chain:\n");
|
||||
for (j = 0; j < sk_X509_num(chain); j++) {
|
||||
X509 *cert = sk_X509_value(chain, j);
|
||||
- printf("depth=%d: ", j);
|
||||
+ BIO_printf(bio_out, "depth=%d: ", j);
|
||||
X509_NAME_print_ex_fp(stdout,
|
||||
X509_get_subject_name(cert),
|
||||
0, get_nameopt());
|
||||
if (j < num_untrusted)
|
||||
- printf(" (untrusted)");
|
||||
- printf("\n");
|
||||
+ BIO_printf(bio_out, " (untrusted)");
|
||||
+ BIO_printf(bio_out, "\n");
|
||||
}
|
||||
sk_X509_pop_free(chain, X509_free);
|
||||
}
|
||||
} else {
|
||||
- printf("error %s: verification failed\n", (file == NULL) ? "stdin" : file);
|
||||
+ BIO_printf(bio_err,
|
||||
+ "error %s: verification failed\n",
|
||||
+ (file == NULL) ? "stdin" : file);
|
||||
}
|
||||
X509_STORE_CTX_free(csc);
|
||||
|
||||
diff --git a/crypto/x509/x_all.c b/crypto/x509/x_all.c
|
||||
index 60a2892..9c8aea5 100644
|
||||
--- a/crypto/x509/x_all.c
|
||||
+++ b/crypto/x509/x_all.c
|
||||
@@ -72,7 +72,10 @@ static int x509_verify_sm2(X509 *x, EVP_PKEY *pkey, int mdnid, int pknid)
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
- if (EVP_PKEY_CTX_set1_id(pctx, x->sm2_id.data, x->sm2_id.length) != 1) {
|
||||
+ /* NOTE: we tolerate no actual ID, to provide maximum flexibility */
|
||||
+ if (x->sm2_id != NULL
|
||||
+ && EVP_PKEY_CTX_set1_id(pctx, x->sm2_id->data,
|
||||
+ x->sm2_id->length) != 1) {
|
||||
X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||
ret = 0;
|
||||
goto err;
|
||||
diff --git a/crypto/x509/x_x509.c b/crypto/x509/x_x509.c
|
||||
index 1beab78..fb03bb2 100644
|
||||
--- a/crypto/x509/x_x509.c
|
||||
+++ b/crypto/x509/x_x509.c
|
||||
@@ -72,6 +72,9 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
#ifndef OPENSSL_NO_RFC3779
|
||||
ret->rfc3779_addr = NULL;
|
||||
ret->rfc3779_asid = NULL;
|
||||
+#endif
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ ret->sm2_id = NULL;
|
||||
#endif
|
||||
ret->aux = NULL;
|
||||
ret->crldp = NULL;
|
||||
@@ -91,6 +94,9 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
|
||||
#ifndef OPENSSL_NO_RFC3779
|
||||
sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free);
|
||||
ASIdentifiers_free(ret->rfc3779_asid);
|
||||
+#endif
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ ASN1_OCTET_STRING_free(ret->sm2_id);
|
||||
#endif
|
||||
break;
|
||||
|
||||
@@ -247,13 +253,14 @@ int X509_get_signature_nid(const X509 *x)
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_SM2
|
||||
-void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id)
|
||||
+void X509_set0_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id)
|
||||
{
|
||||
- x->sm2_id = *sm2_id;
|
||||
+ ASN1_OCTET_STRING_free(x->sm2_id);
|
||||
+ x->sm2_id = sm2_id;
|
||||
}
|
||||
|
||||
ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x)
|
||||
{
|
||||
- return &x->sm2_id;
|
||||
+ return x->sm2_id;
|
||||
}
|
||||
#endif
|
||||
diff --git a/doc/man3/X509_get0_sm2_id.pod b/doc/man3/X509_get0_sm2_id.pod
|
||||
index 84da71e..9698c86 100644
|
||||
--- a/doc/man3/X509_get0_sm2_id.pod
|
||||
+++ b/doc/man3/X509_get0_sm2_id.pod
|
||||
@@ -2,20 +2,24 @@
|
||||
|
||||
=head1 NAME
|
||||
|
||||
-X509_get0_sm2_id, X509_set_sm2_id - get or set SM2 ID for certificate operations
|
||||
+X509_get0_sm2_id, X509_set0_sm2_id - get or set SM2 ID for certificate operations
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
#include <openssl/x509.h>
|
||||
|
||||
ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x);
|
||||
- void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||
+ void X509_set0_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
X509_get0_sm2_id() gets the ID value of an SM2 certificate B<x> by returning an
|
||||
B<ASN1_OCTET_STRING> object which should not be freed by the caller.
|
||||
-X509_set_sm2_id() sets the B<sm2_id> value to an SM2 certificate B<x>.
|
||||
+
|
||||
+X509_set0_sm2_id() sets the B<sm2_id> value to an SM2 certificate B<x>. Calling
|
||||
+this function transfers the memory management of the value to the X509 object,
|
||||
+and therefore the value that has been passed in should not be freed by the
|
||||
+caller after this function has been called.
|
||||
|
||||
=head1 NOTES
|
||||
|
||||
@@ -25,7 +29,7 @@ ability to set and retrieve the SM2 ID value.
|
||||
|
||||
=head1 RETURN VALUES
|
||||
|
||||
-X509_set_sm2_id() does not return a value.
|
||||
+X509_set0_sm2_id() does not return a value.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
diff --git a/include/crypto/x509.h b/include/crypto/x509.h
|
||||
index 418c427..5c314a8 100644
|
||||
--- a/include/crypto/x509.h
|
||||
+++ b/include/crypto/x509.h
|
||||
@@ -186,7 +186,7 @@ struct x509_st {
|
||||
CRYPTO_RWLOCK *lock;
|
||||
volatile int ex_cached;
|
||||
# ifndef OPENSSL_NO_SM2
|
||||
- ASN1_OCTET_STRING sm2_id;
|
||||
+ ASN1_OCTET_STRING *sm2_id;
|
||||
# endif
|
||||
} /* X509 */ ;
|
||||
|
||||
diff --git a/include/openssl/x509.h b/include/openssl/x509.h
|
||||
index 5c88251..a02cf50 100644
|
||||
--- a/include/openssl/x509.h
|
||||
+++ b/include/openssl/x509.h
|
||||
@@ -574,7 +574,7 @@ void X509_get0_signature(const ASN1_BIT_STRING **psig,
|
||||
int X509_get_signature_nid(const X509 *x);
|
||||
|
||||
# ifndef OPENSSL_NO_SM2
|
||||
-void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||
+void X509_set0_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||
ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x);
|
||||
# endif
|
||||
|
||||
diff --git a/test/verify_extra_test.c b/test/verify_extra_test.c
|
||||
index b9959e0..763ea4f 100644
|
||||
--- a/test/verify_extra_test.c
|
||||
+++ b/test/verify_extra_test.c
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
+#include <string.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/x509.h>
|
||||
@@ -231,6 +232,48 @@ static int test_self_signed_bad(void)
|
||||
return test_self_signed(bad_f, 0);
|
||||
}
|
||||
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+static int test_sm2_id(void)
|
||||
+{
|
||||
+ /* we only need an X509 structure, no matter if it's a real SM2 cert */
|
||||
+ X509 *x = NULL;
|
||||
+ BIO *bio = NULL;
|
||||
+ int ret = 0;
|
||||
+ ASN1_OCTET_STRING *v = NULL, *v2 = NULL;
|
||||
+ char *sm2id = "this is an ID";
|
||||
+
|
||||
+ bio = BIO_new_file(bad_f, "r");
|
||||
+ if (bio == NULL)
|
||||
+ goto err;
|
||||
+
|
||||
+ x = PEM_read_bio_X509(bio, NULL, 0, NULL);
|
||||
+ if (x == NULL)
|
||||
+ goto err;
|
||||
+
|
||||
+ v = ASN1_OCTET_STRING_new();
|
||||
+ if (v == NULL)
|
||||
+ goto err;
|
||||
+
|
||||
+ if (!ASN1_OCTET_STRING_set(v, (unsigned char *)sm2id, (int)strlen(sm2id))) {
|
||||
+ ASN1_OCTET_STRING_free(v);
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ X509_set0_sm2_id(x, v);
|
||||
+
|
||||
+ v2 = X509_get0_sm2_id(x);
|
||||
+ if (!TEST_ptr(v2)
|
||||
+ || !TEST_int_eq(ASN1_OCTET_STRING_cmp(v, v2), 0))
|
||||
+ goto err;
|
||||
+
|
||||
+ ret = 1;
|
||||
+ err:
|
||||
+ X509_free(x);
|
||||
+ BIO_free(bio);
|
||||
+ return ret;
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
int setup_tests(void)
|
||||
{
|
||||
if (!TEST_ptr(roots_f = test_get_argument(0))
|
||||
@@ -245,5 +288,8 @@ int setup_tests(void)
|
||||
ADD_TEST(test_store_ctx);
|
||||
ADD_TEST(test_self_signed_good);
|
||||
ADD_TEST(test_self_signed_bad);
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ ADD_TEST(test_sm2_id);
|
||||
+#endif
|
||||
return 1;
|
||||
}
|
||||
diff --git a/util/libcrypto.num b/util/libcrypto.num
|
||||
index 233d1c7..d7abe91 100644
|
||||
--- a/util/libcrypto.num
|
||||
+++ b/util/libcrypto.num
|
||||
@@ -4626,5 +4626,5 @@ FIPS_drbg_get_strength 6379 1_1_0g EXIST::FUNCTION:
|
||||
FIPS_rand_strength 6380 1_1_0g EXIST::FUNCTION:
|
||||
FIPS_drbg_get_blocklength 6381 1_1_0g EXIST::FUNCTION:
|
||||
FIPS_drbg_init 6382 1_1_0g EXIST::FUNCTION:
|
||||
-X509_set_sm2_id 6383 1_1_1m EXIST::FUNCTION:SM2
|
||||
+X509_set0_sm2_id 6383 1_1_1m EXIST::FUNCTION:SM2
|
||||
X509_get0_sm2_id 6384 1_1_1m EXIST::FUNCTION:SM2
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,492 @@
|
||||
From 4d2e328357ac4b468d4762a5a5f615d7e7bf46a6 Mon Sep 17 00:00:00 2001
|
||||
From: Xu Yizhou <xuyizhou1@huawei.com>
|
||||
Date: Thu, 27 Oct 2022 20:49:34 +0800
|
||||
Subject: [PATCH 1/3] SM3 acceleration with SM3 hardware instruction on aarch64
|
||||
|
||||
This patch contains the following two PRs,
|
||||
|
||||
1. SM3 acceleration with SM3 hardware instruction on aarch64
|
||||
|
||||
SM3 hardware instruction is optional feature of crypto extension for
|
||||
aarch64. This implementation accelerates SM3 via SM3 instructions. For
|
||||
the platform not supporting SM3 instruction, the original C
|
||||
implementation still works. Thanks to AliBaba for testing and reporting
|
||||
the following perf numbers for Yitian710:
|
||||
|
||||
Benchmark on T-Head Yitian-710 2.75GHz:
|
||||
|
||||
Before:
|
||||
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes 16384 bytes
|
||||
sm3 49297.82k 121062.63k 223106.05k 283371.52k 307574.10k 309400.92k
|
||||
|
||||
After (33% - 74% faster):
|
||||
type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes 16384 bytes
|
||||
sm3 65640.01k 179121.79k 359854.59k 481448.96k 534055.59k 538274.47k
|
||||
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/17454)
|
||||
|
||||
2. Fix sm3ss1 translation issue in sm3-armv8.pl
|
||||
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/17542)
|
||||
|
||||
Signed-off-by: Xu Yizhou <xuyizhou1@huawei.com>
|
||||
---
|
||||
Configurations/00-base-templates.conf | 1 +
|
||||
Configure | 4 +
|
||||
crypto/arm64cpuid.pl | 7 +
|
||||
crypto/arm_arch.h | 1 +
|
||||
crypto/armcap.c | 10 +
|
||||
crypto/sm3/asm/sm3-armv8.pl | 280 ++++++++++++++++++++++++++
|
||||
crypto/sm3/build.info | 15 +-
|
||||
crypto/sm3/sm3_local.h | 16 +-
|
||||
8 files changed, 332 insertions(+), 2 deletions(-)
|
||||
create mode 100644 crypto/sm3/asm/sm3-armv8.pl
|
||||
|
||||
diff --git a/Configurations/00-base-templates.conf b/Configurations/00-base-templates.conf
|
||||
index 1d35012..a67ae65 100644
|
||||
--- a/Configurations/00-base-templates.conf
|
||||
+++ b/Configurations/00-base-templates.conf
|
||||
@@ -322,6 +322,7 @@ my %targets=(
|
||||
poly1305_asm_src=> "poly1305-armv8.S",
|
||||
keccak1600_asm_src => "keccak1600-armv8.S",
|
||||
sm4_asm_src => "vpsm4_ex-armv8.S",
|
||||
+ sm3_asm_src => "sm3-armv8.S",
|
||||
},
|
||||
parisc11_asm => {
|
||||
template => 1,
|
||||
diff --git a/Configure b/Configure
|
||||
index 3bfe360..fce460d 100755
|
||||
--- a/Configure
|
||||
+++ b/Configure
|
||||
@@ -1423,6 +1423,9 @@ unless ($disabled{asm}) {
|
||||
if ($target{sm4_asm_src} ne "") {
|
||||
push @{$config{lib_defines}}, "VPSM4_EX_ASM";
|
||||
}
|
||||
+ if ($target{sm3_asm_src} ne "") {
|
||||
+ push @{$config{lib_defines}}, "SM3_ASM";
|
||||
+ }
|
||||
}
|
||||
|
||||
my %predefined_C = compiler_predefined($config{CROSS_COMPILE}.$config{CC});
|
||||
@@ -3379,6 +3382,7 @@ sub print_table_entry
|
||||
"multilib",
|
||||
"build_scheme",
|
||||
"sm4_asm_src",
|
||||
+ "sm3_asm_src",
|
||||
);
|
||||
|
||||
if ($type eq "TABLE") {
|
||||
diff --git a/crypto/arm64cpuid.pl b/crypto/arm64cpuid.pl
|
||||
index 319927e..1e9b167 100755
|
||||
--- a/crypto/arm64cpuid.pl
|
||||
+++ b/crypto/arm64cpuid.pl
|
||||
@@ -78,6 +78,13 @@ _armv8_sha512_probe:
|
||||
ret
|
||||
.size _armv8_sha512_probe,.-_armv8_sha512_probe
|
||||
|
||||
+.globl _armv8_sm3_probe
|
||||
+.type _armv8_sm3_probe,%function
|
||||
+_armv8_sm3_probe:
|
||||
+ .long 0xce63c004 // sm3partw1 v4.4s, v0.4s, v3.4s
|
||||
+ ret
|
||||
+.size _armv8_sm3_probe,.-_armv8_sm3_probe
|
||||
+
|
||||
.globl OPENSSL_cleanse
|
||||
.type OPENSSL_cleanse,%function
|
||||
.align 5
|
||||
diff --git a/crypto/arm_arch.h b/crypto/arm_arch.h
|
||||
index 8b71055..8839b21 100644
|
||||
--- a/crypto/arm_arch.h
|
||||
+++ b/crypto/arm_arch.h
|
||||
@@ -80,5 +80,6 @@ extern unsigned int OPENSSL_armcap_P;
|
||||
# define ARMV8_SHA256 (1<<4)
|
||||
# define ARMV8_PMULL (1<<5)
|
||||
# define ARMV8_SHA512 (1<<6)
|
||||
+# define ARMV8_SM3 (1<<9)
|
||||
|
||||
#endif
|
||||
diff --git a/crypto/armcap.c b/crypto/armcap.c
|
||||
index 48c5d4d..8b2f4a5 100644
|
||||
--- a/crypto/armcap.c
|
||||
+++ b/crypto/armcap.c
|
||||
@@ -47,6 +47,7 @@ void _armv8_sha1_probe(void);
|
||||
void _armv8_sha256_probe(void);
|
||||
void _armv8_pmull_probe(void);
|
||||
# ifdef __aarch64__
|
||||
+void _armv8_sm3_probe(void);
|
||||
void _armv8_sha512_probe(void);
|
||||
# endif
|
||||
uint32_t _armv7_tick(void);
|
||||
@@ -130,6 +131,7 @@ static unsigned long getauxval(unsigned long key)
|
||||
# define HWCAP_CE_PMULL (1 << 4)
|
||||
# define HWCAP_CE_SHA1 (1 << 5)
|
||||
# define HWCAP_CE_SHA256 (1 << 6)
|
||||
+# define HWCAP_CE_SM3 (1 << 18)
|
||||
# define HWCAP_CE_SHA512 (1 << 21)
|
||||
# endif
|
||||
|
||||
@@ -190,6 +192,9 @@ void OPENSSL_cpuid_setup(void)
|
||||
# ifdef __aarch64__
|
||||
if (hwcap & HWCAP_CE_SHA512)
|
||||
OPENSSL_armcap_P |= ARMV8_SHA512;
|
||||
+
|
||||
+ if (hwcap & HWCAP_CE_SM3)
|
||||
+ OPENSSL_armcap_P |= ARMV8_SM3;
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
@@ -233,6 +238,11 @@ void OPENSSL_cpuid_setup(void)
|
||||
_armv8_sha512_probe();
|
||||
OPENSSL_armcap_P |= ARMV8_SHA512;
|
||||
}
|
||||
+
|
||||
+ if (sigsetjmp(ill_jmp, 1) == 0) {
|
||||
+ _armv8_sm3_probe();
|
||||
+ OPENSSL_armcap_P |= ARMV8_SM3;
|
||||
+ }
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
diff --git a/crypto/sm3/asm/sm3-armv8.pl b/crypto/sm3/asm/sm3-armv8.pl
|
||||
new file mode 100644
|
||||
index 0000000..677ca52
|
||||
--- /dev/null
|
||||
+++ b/crypto/sm3/asm/sm3-armv8.pl
|
||||
@@ -0,0 +1,280 @@
|
||||
+#! /usr/bin/env perl
|
||||
+# Copyright 2021-2022 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+#
|
||||
+# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
+# this file except in compliance with the License. You can obtain a copy
|
||||
+# in the file LICENSE in the source distribution or at
|
||||
+# https://www.openssl.org/source/license.html
|
||||
+#
|
||||
+# This module implements support for Armv8 SM3 instructions
|
||||
+
|
||||
+# $output is the last argument if it looks like a file (it has an extension)
|
||||
+# $flavour is the first argument if it doesn't look like a file
|
||||
+$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
|
||||
+$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
|
||||
+
|
||||
+$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
+( $xlate="${dir}arm-xlate.pl" and -f $xlate ) or
|
||||
+( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
|
||||
+die "can't locate arm-xlate.pl";
|
||||
+
|
||||
+open OUT,"| \"$^X\" $xlate $flavour \"$output\""
|
||||
+ or die "can't call $xlate: $!";
|
||||
+*STDOUT=*OUT;
|
||||
+
|
||||
+# Message expanding:
|
||||
+# Wj <- P1(W[j-16]^W[j-9]^(W[j-3]<<<15))^(W[j-13]<<<7)^W[j-6]
|
||||
+# Input: s0, s1, s2, s3
|
||||
+# s0 = w0 | w1 | w2 | w3
|
||||
+# s1 = w4 | w5 | w6 | w7
|
||||
+# s2 = w8 | w9 | w10 | w11
|
||||
+# s3 = w12 | w13 | w14 | w15
|
||||
+# Output: s4
|
||||
+sub msg_exp () {
|
||||
+my $s0 = shift;
|
||||
+my $s1 = shift;
|
||||
+my $s2 = shift;
|
||||
+my $s3 = shift;
|
||||
+my $s4 = shift;
|
||||
+my $vtmp1 = shift;
|
||||
+my $vtmp2 = shift;
|
||||
+$code.=<<___;
|
||||
+ // s4 = w7 | w8 | w9 | w10
|
||||
+ ext $s4.16b, $s1.16b, $s2.16b, #12
|
||||
+ // vtmp1 = w3 | w4 | w5 | w6
|
||||
+ ext $vtmp1.16b, $s0.16b, $s1.16b, #12
|
||||
+ // vtmp2 = w10 | w11 | w12 | w13
|
||||
+ ext $vtmp2.16b, $s2.16b, $s3.16b, #8
|
||||
+ sm3partw1 $s4.4s, $s0.4s, $s3.4s
|
||||
+ sm3partw2 $s4.4s, $vtmp2.4s, $vtmp1.4s
|
||||
+___
|
||||
+}
|
||||
+
|
||||
+# A round of compresson function
|
||||
+# Input:
|
||||
+# ab - choose instruction among sm3tt1a, sm3tt1b, sm3tt2a, sm3tt2b
|
||||
+# vstate0 - vstate1, store digest status(A - H)
|
||||
+# vconst0 - vconst1, interleaved used to store Tj <<< j
|
||||
+# vtmp - temporary register
|
||||
+# vw - for sm3tt1ab, vw = s0 eor s1
|
||||
+# s0 - for sm3tt2ab, just be s0
|
||||
+# i, choose wj' or wj from vw
|
||||
+sub round () {
|
||||
+my $ab = shift;
|
||||
+my $vstate0 = shift;
|
||||
+my $vstate1 = shift;
|
||||
+my $vconst0 = shift;
|
||||
+my $vconst1 = shift;
|
||||
+my $vtmp = shift;
|
||||
+my $vw = shift;
|
||||
+my $s0 = shift;
|
||||
+my $i = shift;
|
||||
+$code.=<<___;
|
||||
+ sm3ss1 $vtmp.4s, $vstate0.4s, $vconst0.4s, $vstate1.4s
|
||||
+ shl $vconst1.4s, $vconst0.4s, #1
|
||||
+ sri $vconst1.4s, $vconst0.4s, #31
|
||||
+ sm3tt1$ab $vstate0.4s, $vtmp.4s, $vw.4s[$i]
|
||||
+ sm3tt2$ab $vstate1.4s, $vtmp.4s, $s0.4s[$i]
|
||||
+___
|
||||
+}
|
||||
+
|
||||
+sub qround () {
|
||||
+my $ab = shift;
|
||||
+my $vstate0 = shift;
|
||||
+my $vstate1 = shift;
|
||||
+my $vconst0 = shift;
|
||||
+my $vconst1 = shift;
|
||||
+my $vtmp1 = shift;
|
||||
+my $vtmp2 = shift;
|
||||
+my $s0 = shift;
|
||||
+my $s1 = shift;
|
||||
+my $s2 = shift;
|
||||
+my $s3 = shift;
|
||||
+my $s4 = shift;
|
||||
+ if($s4) {
|
||||
+ &msg_exp($s0, $s1, $s2, $s3, $s4, $vtmp1, $vtmp2);
|
||||
+ }
|
||||
+$code.=<<___;
|
||||
+ eor $vtmp1.16b, $s0.16b, $s1.16b
|
||||
+___
|
||||
+ &round($ab, $vstate0, $vstate1, $vconst0, $vconst1, $vtmp2,
|
||||
+ $vtmp1, $s0, 0);
|
||||
+ &round($ab, $vstate0, $vstate1, $vconst1, $vconst0, $vtmp2,
|
||||
+ $vtmp1, $s0, 1);
|
||||
+ &round($ab, $vstate0, $vstate1, $vconst0, $vconst1, $vtmp2,
|
||||
+ $vtmp1, $s0, 2);
|
||||
+ &round($ab, $vstate0, $vstate1, $vconst1, $vconst0, $vtmp2,
|
||||
+ $vtmp1, $s0, 3);
|
||||
+}
|
||||
+
|
||||
+$code=<<___;
|
||||
+#include "arm_arch.h"
|
||||
+.arch armv8.2-a
|
||||
+.text
|
||||
+___
|
||||
+
|
||||
+{{{
|
||||
+my ($pstate,$pdata,$num)=("x0","x1","w2");
|
||||
+my ($state1,$state2)=("v5","v6");
|
||||
+my ($sconst1, $sconst2)=("s16","s17");
|
||||
+my ($vconst1, $vconst2)=("v16","v17");
|
||||
+my ($s0,$s1,$s2,$s3,$s4)=map("v$_",(0..4));
|
||||
+my ($bkstate1,$bkstate2)=("v18","v19");
|
||||
+my ($vconst_tmp1,$vconst_tmp2)=("v20","v21");
|
||||
+my ($vtmp1,$vtmp2)=("v22","v23");
|
||||
+my $constaddr="x8";
|
||||
+# void ossl_hwsm3_block_data_order(SM3_CTX *c, const void *p, size_t num)
|
||||
+$code.=<<___;
|
||||
+.globl ossl_hwsm3_block_data_order
|
||||
+.type ossl_hwsm3_block_data_order,%function
|
||||
+.align 5
|
||||
+ossl_hwsm3_block_data_order:
|
||||
+ // load state
|
||||
+ ld1 {$state1.4s-$state2.4s}, [$pstate]
|
||||
+ rev64 $state1.4s, $state1.4s
|
||||
+ rev64 $state2.4s, $state2.4s
|
||||
+ ext $state1.16b, $state1.16b, $state1.16b, #8
|
||||
+ ext $state2.16b, $state2.16b, $state2.16b, #8
|
||||
+
|
||||
+ adr $constaddr, .Tj
|
||||
+ ldp $sconst1, $sconst2, [$constaddr]
|
||||
+
|
||||
+.Loop:
|
||||
+ // load input
|
||||
+ ld1 {$s0.16b-$s3.16b}, [$pdata], #64
|
||||
+ sub $num, $num, #1
|
||||
+
|
||||
+ mov $bkstate1.16b, $state1.16b
|
||||
+ mov $bkstate2.16b, $state2.16b
|
||||
+
|
||||
+#ifndef __ARMEB__
|
||||
+ rev32 $s0.16b, $s0.16b
|
||||
+ rev32 $s1.16b, $s1.16b
|
||||
+ rev32 $s2.16b, $s2.16b
|
||||
+ rev32 $s3.16b, $s3.16b
|
||||
+#endif
|
||||
+
|
||||
+ ext $vconst_tmp1.16b, $vconst1.16b, $vconst1.16b, #4
|
||||
+___
|
||||
+ &qround("a",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s0,$s1,$s2,$s3,$s4);
|
||||
+ &qround("a",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s1,$s2,$s3,$s4,$s0);
|
||||
+ &qround("a",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s2,$s3,$s4,$s0,$s1);
|
||||
+ &qround("a",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s3,$s4,$s0,$s1,$s2);
|
||||
+
|
||||
+$code.=<<___;
|
||||
+ ext $vconst_tmp1.16b, $vconst2.16b, $vconst2.16b, #4
|
||||
+___
|
||||
+
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s4,$s0,$s1,$s2,$s3);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s0,$s1,$s2,$s3,$s4);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s1,$s2,$s3,$s4,$s0);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s2,$s3,$s4,$s0,$s1);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s3,$s4,$s0,$s1,$s2);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s4,$s0,$s1,$s2,$s3);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s0,$s1,$s2,$s3,$s4);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s1,$s2,$s3,$s4,$s0);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s2,$s3,$s4,$s0,$s1);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s3,$s4);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s4,$s0);
|
||||
+ &qround("b",$state1,$state2,$vconst_tmp1,$vconst_tmp2,$vtmp1,$vtmp2,
|
||||
+ $s0,$s1);
|
||||
+
|
||||
+$code.=<<___;
|
||||
+ eor $state1.16b, $state1.16b, $bkstate1.16b
|
||||
+ eor $state2.16b, $state2.16b, $bkstate2.16b
|
||||
+
|
||||
+ // any remained blocks?
|
||||
+ cbnz $num, .Loop
|
||||
+
|
||||
+ // save state
|
||||
+ rev64 $state1.4s, $state1.4s
|
||||
+ rev64 $state2.4s, $state2.4s
|
||||
+ ext $state1.16b, $state1.16b, $state1.16b, #8
|
||||
+ ext $state2.16b, $state2.16b, $state2.16b, #8
|
||||
+ st1 {$state1.4s-$state2.4s}, [$pstate]
|
||||
+ ret
|
||||
+.size ossl_hwsm3_block_data_order,.-ossl_hwsm3_block_data_order
|
||||
+
|
||||
+.align 3
|
||||
+.Tj:
|
||||
+.word 0x79cc4519, 0x9d8a7a87
|
||||
+___
|
||||
+}}}
|
||||
+
|
||||
+#########################################
|
||||
+my %sm3partopcode = (
|
||||
+ "sm3partw1" => 0xce60C000,
|
||||
+ "sm3partw2" => 0xce60C400);
|
||||
+
|
||||
+my %sm3ss1opcode = (
|
||||
+ "sm3ss1" => 0xce400000);
|
||||
+
|
||||
+my %sm3ttopcode = (
|
||||
+ "sm3tt1a" => 0xce408000,
|
||||
+ "sm3tt1b" => 0xce408400,
|
||||
+ "sm3tt2a" => 0xce408800,
|
||||
+ "sm3tt2b" => 0xce408C00);
|
||||
+
|
||||
+sub unsm3part {
|
||||
+ my ($mnemonic,$arg)=@_;
|
||||
+
|
||||
+ $arg=~ m/[qv](\d+)[^,]*,\s*[qv](\d+)[^,]*,\s*[qv](\d+)/o
|
||||
+ &&
|
||||
+ sprintf ".inst\t0x%08x\t//%s %s",
|
||||
+ $sm3partopcode{$mnemonic}|$1|($2<<5)|($3<<16),
|
||||
+ $mnemonic,$arg;
|
||||
+}
|
||||
+
|
||||
+sub unsm3ss1 {
|
||||
+ my ($mnemonic,$arg)=@_;
|
||||
+
|
||||
+ $arg=~ m/[qv](\d+)[^,]*,\s*[qv](\d+)[^,]*,\s*[qv](\d+)[^,]*,\s*[qv](\d+)/o
|
||||
+ &&
|
||||
+ sprintf ".inst\t0x%08x\t//%s %s",
|
||||
+ $sm3ss1opcode{$mnemonic}|$1|($2<<5)|($3<<16)|($4<<10),
|
||||
+ $mnemonic,$arg;
|
||||
+}
|
||||
+
|
||||
+sub unsm3tt {
|
||||
+ my ($mnemonic,$arg)=@_;
|
||||
+
|
||||
+ $arg=~ m/[qv](\d+)[^,]*,\s*[qv](\d+)[^,]*,\s*[qv](\d+)[^,]*\[([0-3])\]/o
|
||||
+ &&
|
||||
+ sprintf ".inst\t0x%08x\t//%s %s",
|
||||
+ $sm3ttopcode{$mnemonic}|$1|($2<<5)|($3<<16)|($4<<12),
|
||||
+ $mnemonic,$arg;
|
||||
+}
|
||||
+
|
||||
+open SELF,$0;
|
||||
+while(<SELF>) {
|
||||
+ next if (/^#!/);
|
||||
+ last if (!s/^#/\/\// and !/^$/);
|
||||
+ print;
|
||||
+}
|
||||
+close SELF;
|
||||
+
|
||||
+foreach(split("\n",$code)) {
|
||||
+ s/\`([^\`]*)\`/eval($1)/ge;
|
||||
+
|
||||
+ s/\b(sm3partw[1-2])\s+([qv].*)/unsm3part($1,$2)/ge;
|
||||
+ s/\b(sm3ss1)\s+([qv].*)/unsm3ss1($1,$2)/ge;
|
||||
+ s/\b(sm3tt[1-2][a-b])\s+([qv].*)/unsm3tt($1,$2)/ge;
|
||||
+ print $_,"\n";
|
||||
+}
|
||||
+
|
||||
+close STDOUT or die "error closing STDOUT: $!";
|
||||
diff --git a/crypto/sm3/build.info b/crypto/sm3/build.info
|
||||
index 6009b19..e113729 100644
|
||||
--- a/crypto/sm3/build.info
|
||||
+++ b/crypto/sm3/build.info
|
||||
@@ -1,2 +1,15 @@
|
||||
LIBS=../../libcrypto
|
||||
-SOURCE[../../libcrypto]=sm3.c m_sm3.c
|
||||
+SOURCE[../../libcrypto]=\
|
||||
+ sm3.c m_sm3.c {- $target{sm3_asm_src} -}
|
||||
+
|
||||
+GENERATE[sm3-armv8.S]=asm/sm3-armv8.pl $(PERLASM_SCHEME)
|
||||
+INCLUDE[sm3-armv8.o]=..
|
||||
+
|
||||
+BEGINRAW[Makefile]
|
||||
+##### SM3 assembler implementations
|
||||
+
|
||||
+# GNU make "catch all"
|
||||
+{- $builddir -}/sm3-%.S: {- $sourcedir -}/asm/sm3-%.pl
|
||||
+ CC="$(CC)" $(PERL) $< $(PERLASM_SCHEME) $@
|
||||
+
|
||||
+ENDRAW[Makefile]
|
||||
\ No newline at end of file
|
||||
diff --git a/crypto/sm3/sm3_local.h b/crypto/sm3/sm3_local.h
|
||||
index 7171de5..aafff63 100644
|
||||
--- a/crypto/sm3/sm3_local.h
|
||||
+++ b/crypto/sm3/sm3_local.h
|
||||
@@ -32,7 +32,21 @@
|
||||
ll=(c)->G; (void)HOST_l2c(ll, (s)); \
|
||||
ll=(c)->H; (void)HOST_l2c(ll, (s)); \
|
||||
} while (0)
|
||||
-#define HASH_BLOCK_DATA_ORDER sm3_block_data_order
|
||||
+
|
||||
+#if defined(SM3_ASM)
|
||||
+# if defined(__aarch64__)
|
||||
+# include "crypto/arm_arch.h"
|
||||
+# define HWSM3_CAPABLE (OPENSSL_armcap_P & ARMV8_SM3)
|
||||
+void ossl_hwsm3_block_data_order(SM3_CTX *c, const void *p, size_t num);
|
||||
+# endif
|
||||
+#endif
|
||||
+
|
||||
+#if defined(HWSM3_CAPABLE)
|
||||
+# define HASH_BLOCK_DATA_ORDER (HWSM3_CAPABLE ? ossl_hwsm3_block_data_order \
|
||||
+ : sm3_block_data_order)
|
||||
+#else
|
||||
+# define HASH_BLOCK_DATA_ORDER sm3_block_data_order
|
||||
+#endif
|
||||
|
||||
void sm3_transform(SM3_CTX *c, const unsigned char *data);
|
||||
|
||||
--
|
||||
2.36.1
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,30 @@
|
||||
From f0dd65378296590d87250bf2130bad567483ee3d Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Wed, 3 Apr 2019 09:44:41 +0100
|
||||
Subject: [PATCH 08/15] Skip the correct number of tests if SM2 is disabled
|
||||
|
||||
Fixes no-sm2 (and also no-sm3 and no-ec)
|
||||
|
||||
Reviewed-by: Richard Levitte <levitte@openssl.org>
|
||||
Reviewed-by: Paul Dale <paul.dale@oracle.com>
|
||||
(Merged from https://github.com/openssl/openssl/pull/8650)
|
||||
---
|
||||
test/recipes/25-test_verify.t | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/test/recipes/25-test_verify.t b/test/recipes/25-test_verify.t
|
||||
index b340833..d254bd8 100644
|
||||
--- a/test/recipes/25-test_verify.t
|
||||
+++ b/test/recipes/25-test_verify.t
|
||||
@@ -411,7 +411,7 @@ SKIP: {
|
||||
}
|
||||
|
||||
SKIP: {
|
||||
- skip "SM2 is not supported by this OpenSSL build", 1
|
||||
+ skip "SM2 is not supported by this OpenSSL build", 2
|
||||
if disabled("sm2");
|
||||
|
||||
# Test '-sm2-id' and '-sm2-hex-id' option
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
1189
dependency/openssl/Backport-Support-SM2-certificate-signing.patch
Normal file
1189
dependency/openssl/Backport-Support-SM2-certificate-signing.patch
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,579 @@
|
||||
From 7d86ccd1282aeff8f6d564c5d37625ffcc048f2d Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?=E6=9D=A8=E6=B4=8B?= <yang.yang@baishancloud.com>
|
||||
Date: Fri, 26 Oct 2018 21:34:08 +0800
|
||||
Subject: [PATCH 03/15] Support SM2 certificate verification
|
||||
|
||||
Reviewed-by: Tim Hudson <tjh@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/8321)
|
||||
---
|
||||
apps/verify.c | 45 +++++++++++++--
|
||||
crypto/asn1/a_verify.c | 3 +-
|
||||
crypto/err/openssl.txt | 2 +
|
||||
crypto/objects/obj_dat.h | 17 ++++--
|
||||
crypto/objects/obj_mac.num | 1 +
|
||||
crypto/objects/obj_xref.h | 4 +-
|
||||
crypto/objects/obj_xref.txt | 2 +
|
||||
crypto/objects/objects.txt | 2 +
|
||||
crypto/x509/x509_err.c | 2 +
|
||||
crypto/x509/x_all.c | 110 ++++++++++++++++++++++++++++++++++++
|
||||
crypto/x509/x_x509.c | 12 ++++
|
||||
fuzz/oids.txt | 1 +
|
||||
include/crypto/x509.h | 5 +-
|
||||
include/openssl/obj_mac.h | 7 ++-
|
||||
include/openssl/x509.h | 3 +
|
||||
include/openssl/x509err.h | 2 +
|
||||
util/libcrypto.num | 2 +
|
||||
17 files changed, 204 insertions(+), 16 deletions(-)
|
||||
|
||||
diff --git a/apps/verify.c b/apps/verify.c
|
||||
index 1f93856..09b31cf 100644
|
||||
--- a/apps/verify.c
|
||||
+++ b/apps/verify.c
|
||||
@@ -21,7 +21,8 @@
|
||||
static int cb(int ok, X509_STORE_CTX *ctx);
|
||||
static int check(X509_STORE *ctx, const char *file,
|
||||
STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
|
||||
- STACK_OF(X509_CRL) *crls, int show_chain);
|
||||
+ STACK_OF(X509_CRL) *crls, int show_chain,
|
||||
+ unsigned char *sm2id, size_t sm2idlen);
|
||||
static int v_verbose = 0, vflags = 0;
|
||||
|
||||
typedef enum OPTION_choice {
|
||||
@@ -29,7 +30,7 @@ typedef enum OPTION_choice {
|
||||
OPT_ENGINE, OPT_CAPATH, OPT_CAFILE, OPT_NOCAPATH, OPT_NOCAFILE,
|
||||
OPT_UNTRUSTED, OPT_TRUSTED, OPT_CRLFILE, OPT_CRL_DOWNLOAD, OPT_SHOW_CHAIN,
|
||||
OPT_V_ENUM, OPT_NAMEOPT,
|
||||
- OPT_VERBOSE
|
||||
+ OPT_VERBOSE, OPT_SM2ID, OPT_SM2HEXID
|
||||
} OPTION_CHOICE;
|
||||
|
||||
const OPTIONS verify_options[] = {
|
||||
@@ -56,6 +57,12 @@ const OPTIONS verify_options[] = {
|
||||
OPT_V_OPTIONS,
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
{"engine", OPT_ENGINE, 's', "Use engine, possibly a hardware device"},
|
||||
+#endif
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ {"sm2-id", OPT_SM2ID, 's',
|
||||
+ "Specify an ID string to verify an SM2 certificate"},
|
||||
+ {"sm2-hex-id", OPT_SM2HEXID, 's',
|
||||
+ "Specify a hex ID string to verify an SM2 certificate"},
|
||||
#endif
|
||||
{NULL}
|
||||
};
|
||||
@@ -71,6 +78,8 @@ int verify_main(int argc, char **argv)
|
||||
int noCApath = 0, noCAfile = 0;
|
||||
int vpmtouched = 0, crl_download = 0, show_chain = 0, i = 0, ret = 1;
|
||||
OPTION_CHOICE o;
|
||||
+ unsigned char *sm2_id = NULL;
|
||||
+ size_t sm2_idlen = 0;
|
||||
|
||||
if ((vpm = X509_VERIFY_PARAM_new()) == NULL)
|
||||
goto end;
|
||||
@@ -158,6 +167,19 @@ int verify_main(int argc, char **argv)
|
||||
case OPT_VERBOSE:
|
||||
v_verbose = 1;
|
||||
break;
|
||||
+ case OPT_SM2ID:
|
||||
+ /* we assume the input is not a hex string */
|
||||
+ sm2_id = (unsigned char *)opt_arg();
|
||||
+ sm2_idlen = strlen((const char *)sm2_id);
|
||||
+ break;
|
||||
+ case OPT_SM2HEXID:
|
||||
+ /* try to parse the input as hex string first */
|
||||
+ sm2_id = OPENSSL_hexstr2buf(opt_arg(), (long *)&sm2_idlen);
|
||||
+ if (sm2_id == NULL) {
|
||||
+ BIO_printf(bio_err, "Invalid hex string input\n");
|
||||
+ goto end;
|
||||
+ }
|
||||
+ break;
|
||||
}
|
||||
}
|
||||
argc = opt_num_rest();
|
||||
@@ -183,12 +205,13 @@ int verify_main(int argc, char **argv)
|
||||
|
||||
ret = 0;
|
||||
if (argc < 1) {
|
||||
- if (check(store, NULL, untrusted, trusted, crls, show_chain) != 1)
|
||||
+ if (check(store, NULL, untrusted, trusted, crls, show_chain,
|
||||
+ sm2_id, sm2_idlen) != 1)
|
||||
ret = -1;
|
||||
} else {
|
||||
for (i = 0; i < argc; i++)
|
||||
if (check(store, argv[i], untrusted, trusted, crls,
|
||||
- show_chain) != 1)
|
||||
+ show_chain, sm2_id, sm2_idlen) != 1)
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
@@ -204,7 +227,8 @@ int verify_main(int argc, char **argv)
|
||||
|
||||
static int check(X509_STORE *ctx, const char *file,
|
||||
STACK_OF(X509) *uchain, STACK_OF(X509) *tchain,
|
||||
- STACK_OF(X509_CRL) *crls, int show_chain)
|
||||
+ STACK_OF(X509_CRL) *crls, int show_chain,
|
||||
+ unsigned char *sm2id, size_t sm2idlen)
|
||||
{
|
||||
X509 *x = NULL;
|
||||
int i = 0, ret = 0;
|
||||
@@ -216,6 +240,17 @@ static int check(X509_STORE *ctx, const char *file,
|
||||
if (x == NULL)
|
||||
goto end;
|
||||
|
||||
+ if (sm2id != NULL) {
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ ASN1_OCTET_STRING v;
|
||||
+
|
||||
+ v.data = sm2id;
|
||||
+ v.length = sm2idlen;
|
||||
+
|
||||
+ X509_set_sm2_id(x, &v);
|
||||
+#endif
|
||||
+ }
|
||||
+
|
||||
csc = X509_STORE_CTX_new();
|
||||
if (csc == NULL) {
|
||||
printf("error %s: X.509 store context allocation failed\n",
|
||||
diff --git a/crypto/asn1/a_verify.c b/crypto/asn1/a_verify.c
|
||||
index 4b5f542..f543aa1 100644
|
||||
--- a/crypto/asn1/a_verify.c
|
||||
+++ b/crypto/asn1/a_verify.c
|
||||
@@ -94,7 +94,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||
int mdnid, pknid;
|
||||
size_t inll = 0;
|
||||
|
||||
- if (!pkey) {
|
||||
+ if (pkey == NULL) {
|
||||
ASN1err(ASN1_F_ASN1_ITEM_VERIFY, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return -1;
|
||||
}
|
||||
@@ -150,7 +150,6 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
|
||||
ret = 0;
|
||||
goto err;
|
||||
}
|
||||
-
|
||||
}
|
||||
|
||||
inl = ASN1_item_i2d(asn, &buf_in, it);
|
||||
diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt
|
||||
index 902e97b..5e71e65 100644
|
||||
--- a/crypto/err/openssl.txt
|
||||
+++ b/crypto/err/openssl.txt
|
||||
@@ -1766,8 +1766,10 @@ X509_F_X509_STORE_NEW:158:X509_STORE_new
|
||||
X509_F_X509_TO_X509_REQ:126:X509_to_X509_REQ
|
||||
X509_F_X509_TRUST_ADD:133:X509_TRUST_add
|
||||
X509_F_X509_TRUST_SET:141:X509_TRUST_set
|
||||
+X509_F_X509_VERIFY:161:X509_verify
|
||||
X509_F_X509_VERIFY_CERT:127:X509_verify_cert
|
||||
X509_F_X509_VERIFY_PARAM_NEW:159:X509_VERIFY_PARAM_new
|
||||
+X509_F_X509_VERIFY_SM2:162:x509_verify_sm2
|
||||
|
||||
#Reason codes
|
||||
ASN1_R_ADDING_OBJECT:171:adding object
|
||||
diff --git a/crypto/objects/obj_dat.h b/crypto/objects/obj_dat.h
|
||||
index 24b49a2..eb4cce4 100644
|
||||
--- a/crypto/objects/obj_dat.h
|
||||
+++ b/crypto/objects/obj_dat.h
|
||||
@@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/objects/obj_dat.pl
|
||||
*
|
||||
- * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+ * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
@@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/* Serialized OID's */
|
||||
-static const unsigned char so[7762] = {
|
||||
+static const unsigned char so[7770] = {
|
||||
0x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */
|
||||
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */
|
||||
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */
|
||||
@@ -1076,9 +1076,10 @@ static const unsigned char so[7762] = {
|
||||
0x2A,0x85,0x03,0x07,0x01,0x02,0x01,0x01,0x04, /* [ 7736] OBJ_id_tc26_gost_3410_2012_256_paramSetD */
|
||||
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x0C, /* [ 7745] OBJ_hmacWithSHA512_224 */
|
||||
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x0D, /* [ 7753] OBJ_hmacWithSHA512_256 */
|
||||
+ 0x2A,0x81,0x1C,0xCF,0x55,0x01,0x83,0x75, /* [ 7761] OBJ_SM2_with_SM3 */
|
||||
};
|
||||
|
||||
-#define NUM_NID 1195
|
||||
+#define NUM_NID 1196
|
||||
static const ASN1_OBJECT nid_objs[NUM_NID] = {
|
||||
{"UNDEF", "undefined", NID_undef},
|
||||
{"rsadsi", "RSA Data Security, Inc.", NID_rsadsi, 6, &so[0]},
|
||||
@@ -2275,9 +2276,10 @@ static const ASN1_OBJECT nid_objs[NUM_NID] = {
|
||||
{"magma-mac", "magma-mac", NID_magma_mac},
|
||||
{"hmacWithSHA512-224", "hmacWithSHA512-224", NID_hmacWithSHA512_224, 8, &so[7745]},
|
||||
{"hmacWithSHA512-256", "hmacWithSHA512-256", NID_hmacWithSHA512_256, 8, &so[7753]},
|
||||
+ {"SM2-SM3", "SM2-with-SM3", NID_SM2_with_SM3, 8, &so[7761]},
|
||||
};
|
||||
|
||||
-#define NUM_SN 1186
|
||||
+#define NUM_SN 1187
|
||||
static const unsigned int sn_objs[NUM_SN] = {
|
||||
364, /* "AD_DVCS" */
|
||||
419, /* "AES-128-CBC" */
|
||||
@@ -2543,6 +2545,7 @@ static const unsigned int sn_objs[NUM_SN] = {
|
||||
1100, /* "SHAKE128" */
|
||||
1101, /* "SHAKE256" */
|
||||
1172, /* "SM2" */
|
||||
+ 1195, /* "SM2-SM3" */
|
||||
1143, /* "SM3" */
|
||||
1134, /* "SM4-CBC" */
|
||||
1137, /* "SM4-CFB" */
|
||||
@@ -3467,7 +3470,7 @@ static const unsigned int sn_objs[NUM_SN] = {
|
||||
1093, /* "x509ExtAdmission" */
|
||||
};
|
||||
|
||||
-#define NUM_LN 1186
|
||||
+#define NUM_LN 1187
|
||||
static const unsigned int ln_objs[NUM_LN] = {
|
||||
363, /* "AD Time Stamping" */
|
||||
405, /* "ANSI X9.62" */
|
||||
@@ -3623,6 +3626,7 @@ static const unsigned int ln_objs[NUM_LN] = {
|
||||
1119, /* "RSA-SHA3-512" */
|
||||
188, /* "S/MIME" */
|
||||
167, /* "S/MIME Capabilities" */
|
||||
+ 1195, /* "SM2-with-SM3" */
|
||||
1006, /* "SNILS" */
|
||||
387, /* "SNMPv2" */
|
||||
1025, /* "SSH Client" */
|
||||
@@ -4657,7 +4661,7 @@ static const unsigned int ln_objs[NUM_LN] = {
|
||||
125, /* "zlib compression" */
|
||||
};
|
||||
|
||||
-#define NUM_OBJ 1071
|
||||
+#define NUM_OBJ 1072
|
||||
static const unsigned int obj_objs[NUM_OBJ] = {
|
||||
0, /* OBJ_undef 0 */
|
||||
181, /* OBJ_iso 1 */
|
||||
@@ -5126,6 +5130,7 @@ static const unsigned int obj_objs[NUM_OBJ] = {
|
||||
1139, /* OBJ_sm4_ctr 1 2 156 10197 1 104 7 */
|
||||
1172, /* OBJ_sm2 1 2 156 10197 1 301 */
|
||||
1143, /* OBJ_sm3 1 2 156 10197 1 401 */
|
||||
+ 1195, /* OBJ_SM2_with_SM3 1 2 156 10197 1 501 */
|
||||
1144, /* OBJ_sm3WithRSAEncryption 1 2 156 10197 1 504 */
|
||||
776, /* OBJ_seed_ecb 1 2 410 200004 1 3 */
|
||||
777, /* OBJ_seed_cbc 1 2 410 200004 1 4 */
|
||||
diff --git a/crypto/objects/obj_mac.num b/crypto/objects/obj_mac.num
|
||||
index 1b6a9c6..8b797b0 100644
|
||||
--- a/crypto/objects/obj_mac.num
|
||||
+++ b/crypto/objects/obj_mac.num
|
||||
@@ -1192,3 +1192,4 @@ magma_cfb 1191
|
||||
magma_mac 1192
|
||||
hmacWithSHA512_224 1193
|
||||
hmacWithSHA512_256 1194
|
||||
+SM2_with_SM3 1195
|
||||
diff --git a/crypto/objects/obj_xref.h b/crypto/objects/obj_xref.h
|
||||
index 5c3561a..1acfcde 100644
|
||||
--- a/crypto/objects/obj_xref.h
|
||||
+++ b/crypto/objects/obj_xref.h
|
||||
@@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by objxref.pl
|
||||
*
|
||||
- * Copyright 1998-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+ * Copyright 1998-2022 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -79,6 +79,7 @@ static const nid_triple sigoid_srt[] = {
|
||||
{NID_RSA_SHA3_256, NID_sha3_256, NID_rsaEncryption},
|
||||
{NID_RSA_SHA3_384, NID_sha3_384, NID_rsaEncryption},
|
||||
{NID_RSA_SHA3_512, NID_sha3_512, NID_rsaEncryption},
|
||||
+ {NID_SM2_with_SM3, NID_sm3, NID_sm2},
|
||||
};
|
||||
|
||||
static const nid_triple *const sigoid_srt_xref[] = {
|
||||
@@ -125,4 +126,5 @@ static const nid_triple *const sigoid_srt_xref[] = {
|
||||
&sigoid_srt[45],
|
||||
&sigoid_srt[46],
|
||||
&sigoid_srt[47],
|
||||
+ &sigoid_srt[48],
|
||||
};
|
||||
diff --git a/crypto/objects/obj_xref.txt b/crypto/objects/obj_xref.txt
|
||||
index ca3e744..f3dd8ed 100644
|
||||
--- a/crypto/objects/obj_xref.txt
|
||||
+++ b/crypto/objects/obj_xref.txt
|
||||
@@ -64,3 +64,5 @@ dhSinglePass_cofactorDH_sha224kdf_scheme sha224 dh_cofactor_kdf
|
||||
dhSinglePass_cofactorDH_sha256kdf_scheme sha256 dh_cofactor_kdf
|
||||
dhSinglePass_cofactorDH_sha384kdf_scheme sha384 dh_cofactor_kdf
|
||||
dhSinglePass_cofactorDH_sha512kdf_scheme sha512 dh_cofactor_kdf
|
||||
+
|
||||
+SM2_with_SM3 sm3 sm2
|
||||
diff --git a/crypto/objects/objects.txt b/crypto/objects/objects.txt
|
||||
index c49d4c5..be9da47 100644
|
||||
--- a/crypto/objects/objects.txt
|
||||
+++ b/crypto/objects/objects.txt
|
||||
@@ -385,6 +385,8 @@ sm-scheme 301 : SM2 : sm2
|
||||
sm-scheme 401 : SM3 : sm3
|
||||
sm-scheme 504 : RSA-SM3 : sm3WithRSAEncryption
|
||||
|
||||
+sm-scheme 501 : SM2-SM3 : SM2-with-SM3
|
||||
+
|
||||
# From RFC4231
|
||||
rsadsi 2 8 : : hmacWithSHA224
|
||||
rsadsi 2 9 : : hmacWithSHA256
|
||||
diff --git a/crypto/x509/x509_err.c b/crypto/x509/x509_err.c
|
||||
index bdd1e67..c91ad7c 100644
|
||||
--- a/crypto/x509/x509_err.c
|
||||
+++ b/crypto/x509/x509_err.c
|
||||
@@ -105,9 +105,11 @@ static const ERR_STRING_DATA X509_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_X509, X509_F_X509_TO_X509_REQ, 0), "X509_to_X509_REQ"},
|
||||
{ERR_PACK(ERR_LIB_X509, X509_F_X509_TRUST_ADD, 0), "X509_TRUST_add"},
|
||||
{ERR_PACK(ERR_LIB_X509, X509_F_X509_TRUST_SET, 0), "X509_TRUST_set"},
|
||||
+ {ERR_PACK(ERR_LIB_X509, X509_F_X509_VERIFY, 0), "X509_verify"},
|
||||
{ERR_PACK(ERR_LIB_X509, X509_F_X509_VERIFY_CERT, 0), "X509_verify_cert"},
|
||||
{ERR_PACK(ERR_LIB_X509, X509_F_X509_VERIFY_PARAM_NEW, 0),
|
||||
"X509_VERIFY_PARAM_new"},
|
||||
+ {ERR_PACK(ERR_LIB_X509, X509_F_X509_VERIFY_SM2, 0), "x509_verify_sm2"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
diff --git a/crypto/x509/x_all.c b/crypto/x509/x_all.c
|
||||
index a4e9cda..60a2892 100644
|
||||
--- a/crypto/x509/x_all.c
|
||||
+++ b/crypto/x509/x_all.c
|
||||
@@ -19,10 +19,120 @@
|
||||
#include <openssl/dsa.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+
|
||||
+# include "crypto/asn1.h"
|
||||
+# include "crypto/evp.h"
|
||||
+
|
||||
+static int x509_verify_sm2(X509 *x, EVP_PKEY *pkey, int mdnid, int pknid)
|
||||
+{
|
||||
+ EVP_MD_CTX *ctx = NULL;
|
||||
+ unsigned char *buf_in = NULL;
|
||||
+ int ret = -1, inl = 0;
|
||||
+ size_t inll = 0;
|
||||
+ EVP_PKEY_CTX *pctx = NULL;
|
||||
+ const EVP_MD *type = EVP_get_digestbynid(mdnid);
|
||||
+
|
||||
+ if (type == NULL) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2,
|
||||
+ ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ if (pkey == NULL) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_PASSED_NULL_PARAMETER);
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (x->signature.type == V_ASN1_BIT_STRING && x->signature.flags & 0x7) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ ctx = EVP_MD_CTX_new();
|
||||
+ if (ctx == NULL) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_MALLOC_FAILURE);
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ /* Check public key OID matches public key type */
|
||||
+ if (EVP_PKEY_type(pknid) != pkey->ameth->pkey_id) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ASN1_R_WRONG_PUBLIC_KEY_TYPE);
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ if (!EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2)) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||
+ ret = 0;
|
||||
+ goto err;
|
||||
+ }
|
||||
+ pctx = EVP_PKEY_CTX_new(pkey, NULL);
|
||||
+ if (pctx == NULL) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||
+ ret = 0;
|
||||
+ goto err;
|
||||
+ }
|
||||
+ if (EVP_PKEY_CTX_set1_id(pctx, x->sm2_id.data, x->sm2_id.length) != 1) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||
+ ret = 0;
|
||||
+ goto err;
|
||||
+ }
|
||||
+ EVP_MD_CTX_set_pkey_ctx(ctx, pctx);
|
||||
+
|
||||
+ if (!EVP_DigestVerifyInit(ctx, NULL, type, NULL, pkey)) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||
+ ret = 0;
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ inl = ASN1_item_i2d((ASN1_VALUE *)&x->cert_info, &buf_in,
|
||||
+ ASN1_ITEM_rptr(X509_CINF));
|
||||
+ if (inl <= 0) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_INTERNAL_ERROR);
|
||||
+ goto err;
|
||||
+ }
|
||||
+ if (buf_in == NULL) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_MALLOC_FAILURE);
|
||||
+ goto err;
|
||||
+ }
|
||||
+ inll = inl;
|
||||
+
|
||||
+ ret = EVP_DigestVerify(ctx, x->signature.data,
|
||||
+ (size_t)x->signature.length, buf_in, inl);
|
||||
+ if (ret <= 0) {
|
||||
+ X509err(X509_F_X509_VERIFY_SM2, ERR_R_EVP_LIB);
|
||||
+ goto err;
|
||||
+ }
|
||||
+ ret = 1;
|
||||
+ err:
|
||||
+ OPENSSL_clear_free(buf_in, inll);
|
||||
+ EVP_MD_CTX_free(ctx);
|
||||
+ EVP_PKEY_CTX_free(pctx);
|
||||
+ return ret;
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
int X509_verify(X509 *a, EVP_PKEY *r)
|
||||
{
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ int mdnid, pknid;
|
||||
+#endif
|
||||
+
|
||||
if (X509_ALGOR_cmp(&a->sig_alg, &a->cert_info.signature))
|
||||
return 0;
|
||||
+
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ /* Convert signature OID into digest and public key OIDs */
|
||||
+ if (!OBJ_find_sigid_algs(OBJ_obj2nid(a->sig_alg.algorithm),
|
||||
+ &mdnid, &pknid)) {
|
||||
+ X509err(X509_F_X509_VERIFY, ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ if (pknid == NID_sm2)
|
||||
+ return x509_verify_sm2(a, r, mdnid, pknid);
|
||||
+#endif
|
||||
+
|
||||
return (ASN1_item_verify(ASN1_ITEM_rptr(X509_CINF), &a->sig_alg,
|
||||
&a->signature, &a->cert_info, r));
|
||||
}
|
||||
diff --git a/crypto/x509/x_x509.c b/crypto/x509/x_x509.c
|
||||
index 7aa8b77..1beab78 100644
|
||||
--- a/crypto/x509/x_x509.c
|
||||
+++ b/crypto/x509/x_x509.c
|
||||
@@ -245,3 +245,15 @@ int X509_get_signature_nid(const X509 *x)
|
||||
{
|
||||
return OBJ_obj2nid(x->sig_alg.algorithm);
|
||||
}
|
||||
+
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id)
|
||||
+{
|
||||
+ x->sm2_id = *sm2_id;
|
||||
+}
|
||||
+
|
||||
+ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x)
|
||||
+{
|
||||
+ return &x->sm2_id;
|
||||
+}
|
||||
+#endif
|
||||
diff --git a/fuzz/oids.txt b/fuzz/oids.txt
|
||||
index eda55e4..8dfdea9 100644
|
||||
--- a/fuzz/oids.txt
|
||||
+++ b/fuzz/oids.txt
|
||||
@@ -1063,3 +1063,4 @@ OBJ_id_tc26_gost_3410_2012_256_paramSetC="\x2A\x85\x03\x07\x01\x02\x01\x01\x03"
|
||||
OBJ_id_tc26_gost_3410_2012_256_paramSetD="\x2A\x85\x03\x07\x01\x02\x01\x01\x04"
|
||||
OBJ_hmacWithSHA512_224="\x2A\x86\x48\x86\xF7\x0D\x02\x0C"
|
||||
OBJ_hmacWithSHA512_256="\x2A\x86\x48\x86\xF7\x0D\x02\x0D"
|
||||
+OBJ_SM2_with_SM3="\x2A\x81\x1C\xCF\x55\x01\x83\x75"
|
||||
diff --git a/include/crypto/x509.h b/include/crypto/x509.h
|
||||
index 243ea74..418c427 100644
|
||||
--- a/include/crypto/x509.h
|
||||
+++ b/include/crypto/x509.h
|
||||
@@ -177,7 +177,7 @@ struct x509_st {
|
||||
STACK_OF(DIST_POINT) *crldp;
|
||||
STACK_OF(GENERAL_NAME) *altname;
|
||||
NAME_CONSTRAINTS *nc;
|
||||
-#ifndef OPENSSL_NO_RFC3779
|
||||
+# ifndef OPENSSL_NO_RFC3779
|
||||
STACK_OF(IPAddressFamily) *rfc3779_addr;
|
||||
struct ASIdentifiers_st *rfc3779_asid;
|
||||
# endif
|
||||
@@ -185,6 +185,9 @@ struct x509_st {
|
||||
X509_CERT_AUX *aux;
|
||||
CRYPTO_RWLOCK *lock;
|
||||
volatile int ex_cached;
|
||||
+# ifndef OPENSSL_NO_SM2
|
||||
+ ASN1_OCTET_STRING sm2_id;
|
||||
+# endif
|
||||
} /* X509 */ ;
|
||||
|
||||
/*
|
||||
diff --git a/include/openssl/obj_mac.h b/include/openssl/obj_mac.h
|
||||
index eb812ed..9b125c1 100644
|
||||
--- a/include/openssl/obj_mac.h
|
||||
+++ b/include/openssl/obj_mac.h
|
||||
@@ -2,7 +2,7 @@
|
||||
* WARNING: do not edit!
|
||||
* Generated by crypto/objects/objects.pl
|
||||
*
|
||||
- * Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+ * Copyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
@@ -1179,6 +1179,11 @@
|
||||
#define NID_sm3WithRSAEncryption 1144
|
||||
#define OBJ_sm3WithRSAEncryption OBJ_sm_scheme,504L
|
||||
|
||||
+#define SN_SM2_with_SM3 "SM2-SM3"
|
||||
+#define LN_SM2_with_SM3 "SM2-with-SM3"
|
||||
+#define NID_SM2_with_SM3 1195
|
||||
+#define OBJ_SM2_with_SM3 OBJ_sm_scheme,501L
|
||||
+
|
||||
#define LN_hmacWithSHA224 "hmacWithSHA224"
|
||||
#define NID_hmacWithSHA224 798
|
||||
#define OBJ_hmacWithSHA224 OBJ_rsadsi,2L,8L
|
||||
diff --git a/include/openssl/x509.h b/include/openssl/x509.h
|
||||
index 3ff86ec..5f17057 100644
|
||||
--- a/include/openssl/x509.h
|
||||
+++ b/include/openssl/x509.h
|
||||
@@ -573,6 +573,9 @@ void X509_get0_signature(const ASN1_BIT_STRING **psig,
|
||||
const X509_ALGOR **palg, const X509 *x);
|
||||
int X509_get_signature_nid(const X509 *x);
|
||||
|
||||
+void X509_set_sm2_id(X509 *x, ASN1_OCTET_STRING *sm2_id);
|
||||
+ASN1_OCTET_STRING *X509_get0_sm2_id(X509 *x);
|
||||
+
|
||||
int X509_trusted(const X509 *x);
|
||||
int X509_alias_set1(X509 *x, const unsigned char *name, int len);
|
||||
int X509_keyid_set1(X509 *x, const unsigned char *id, int len);
|
||||
diff --git a/include/openssl/x509err.h b/include/openssl/x509err.h
|
||||
index cd08673..06d75f0 100644
|
||||
--- a/include/openssl/x509err.h
|
||||
+++ b/include/openssl/x509err.h
|
||||
@@ -81,8 +81,10 @@ int ERR_load_X509_strings(void);
|
||||
# define X509_F_X509_TO_X509_REQ 126
|
||||
# define X509_F_X509_TRUST_ADD 133
|
||||
# define X509_F_X509_TRUST_SET 141
|
||||
+# define X509_F_X509_VERIFY 161
|
||||
# define X509_F_X509_VERIFY_CERT 127
|
||||
# define X509_F_X509_VERIFY_PARAM_NEW 159
|
||||
+# define X509_F_X509_VERIFY_SM2 162
|
||||
|
||||
/*
|
||||
* X509 reason codes.
|
||||
diff --git a/util/libcrypto.num b/util/libcrypto.num
|
||||
index 1566231..8635ac4 100644
|
||||
--- a/util/libcrypto.num
|
||||
+++ b/util/libcrypto.num
|
||||
@@ -4626,3 +4626,5 @@ FIPS_drbg_get_strength 6379 1_1_0g EXIST::FUNCTION:
|
||||
FIPS_rand_strength 6380 1_1_0g EXIST::FUNCTION:
|
||||
FIPS_drbg_get_blocklength 6381 1_1_0g EXIST::FUNCTION:
|
||||
FIPS_drbg_init 6382 1_1_0g EXIST::FUNCTION:
|
||||
+X509_set_sm2_id 6383 1_1_1m EXIST::FUNCTION:
|
||||
+X509_get0_sm2_id 6384 1_1_1m EXIST::FUNCTION:
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,127 @@
|
||||
From 1d9e832e41858b13a96899d842afd183f1c66c48 Mon Sep 17 00:00:00 2001
|
||||
From: Paul Yang <kaishen.yy@antfin.com>
|
||||
Date: Tue, 30 Jul 2019 23:05:44 +0800
|
||||
Subject: [PATCH 11/15] Support parsing of SM2 ID in hexdecimal
|
||||
|
||||
The current EVP_PEKY_ctrl for SM2 has no capability of parsing an ID
|
||||
input in hexdecimal.
|
||||
|
||||
The newly added ctrl string is called: sm2_hex_id
|
||||
|
||||
Test cases and documentation are updated.
|
||||
|
||||
Reviewed-by: Tim Hudson <tjh@openssl.org>
|
||||
Reviewed-by: Richard Levitte <levitte@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/9584)
|
||||
---
|
||||
crypto/sm2/sm2_pmeth.c | 19 +++++++++++++++++++
|
||||
doc/man1/pkeyutl.pod | 7 +++++++
|
||||
include/openssl/ec.h | 1 -
|
||||
test/recipes/25-test_req.t | 15 +++++++++++++--
|
||||
4 files changed, 39 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/crypto/sm2/sm2_pmeth.c b/crypto/sm2/sm2_pmeth.c
|
||||
index 837bdc1..9551d70 100644
|
||||
--- a/crypto/sm2/sm2_pmeth.c
|
||||
+++ b/crypto/sm2/sm2_pmeth.c
|
||||
@@ -232,6 +232,10 @@ static int pkey_sm2_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||
static int pkey_sm2_ctrl_str(EVP_PKEY_CTX *ctx,
|
||||
const char *type, const char *value)
|
||||
{
|
||||
+ uint8_t *hex_id;
|
||||
+ long hex_len = 0;
|
||||
+ int ret = 0;
|
||||
+
|
||||
if (strcmp(type, "ec_paramgen_curve") == 0) {
|
||||
int nid = NID_undef;
|
||||
|
||||
@@ -255,6 +259,21 @@ static int pkey_sm2_ctrl_str(EVP_PKEY_CTX *ctx,
|
||||
} else if (strcmp(type, "sm2_id") == 0) {
|
||||
return pkey_sm2_ctrl(ctx, EVP_PKEY_CTRL_SET1_ID,
|
||||
(int)strlen(value), (void *)value);
|
||||
+ } else if (strcmp(type, "sm2_hex_id") == 0) {
|
||||
+ /*
|
||||
+ * TODO(3.0): reconsider the name "sm2_hex_id", OR change
|
||||
+ * OSSL_PARAM_construct_from_text() / OSSL_PARAM_allocate_from_text()
|
||||
+ * to handle infix "_hex_"
|
||||
+ */
|
||||
+ hex_id = OPENSSL_hexstr2buf((const char *)value, &hex_len);
|
||||
+ if (hex_id == NULL) {
|
||||
+ SM2err(SM2_F_PKEY_SM2_CTRL_STR, ERR_R_PASSED_INVALID_ARGUMENT);
|
||||
+ return 0;
|
||||
+ }
|
||||
+ ret = pkey_sm2_ctrl(ctx, EVP_PKEY_CTRL_SET1_ID, (int)hex_len,
|
||||
+ (void *)hex_id);
|
||||
+ OPENSSL_free(hex_id);
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
return -2;
|
||||
diff --git a/doc/man1/pkeyutl.pod b/doc/man1/pkeyutl.pod
|
||||
index f0f80af..1a742ab 100644
|
||||
--- a/doc/man1/pkeyutl.pod
|
||||
+++ b/doc/man1/pkeyutl.pod
|
||||
@@ -329,6 +329,13 @@ This sets the ID string used in SM2 sign or verify operations. While verifying
|
||||
an SM2 signature, the ID string must be the same one used when signing the data.
|
||||
Otherwise the verification will fail.
|
||||
|
||||
+=item B<sm2_hex_id:hex_string>
|
||||
+
|
||||
+This sets the ID string used in SM2 sign or verify operations. While verifying
|
||||
+an SM2 signature, the ID string must be the same one used when signing the data.
|
||||
+Otherwise the verification will fail. The ID string provided with this option
|
||||
+should be a valid hexadecimal value.
|
||||
+
|
||||
=back
|
||||
|
||||
=head1 EXAMPLES
|
||||
diff --git a/include/openssl/ec.h b/include/openssl/ec.h
|
||||
index 24baf53..e8c8869 100644
|
||||
--- a/include/openssl/ec.h
|
||||
+++ b/include/openssl/ec.h
|
||||
@@ -1444,7 +1444,6 @@ void EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth,
|
||||
# define EVP_PKEY_CTX_set1_id(ctx, id, id_len) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
|
||||
EVP_PKEY_CTRL_SET1_ID, (int)id_len, (void*)(id))
|
||||
-
|
||||
# define EVP_PKEY_CTX_get1_id(ctx, id) \
|
||||
EVP_PKEY_CTX_ctrl(ctx, -1, -1, \
|
||||
EVP_PKEY_CTRL_GET1_ID, 0, (void*)(id))
|
||||
diff --git a/test/recipes/25-test_req.t b/test/recipes/25-test_req.t
|
||||
index 8289959..d53e577 100644
|
||||
--- a/test/recipes/25-test_req.t
|
||||
+++ b/test/recipes/25-test_req.t
|
||||
@@ -182,10 +182,10 @@ subtest "generating certificate requests" => sub {
|
||||
};
|
||||
|
||||
subtest "generating SM2 certificate requests" => sub {
|
||||
- plan tests => 2;
|
||||
+ plan tests => 4;
|
||||
|
||||
SKIP: {
|
||||
- skip "SM2 is not supported by this OpenSSL build", 2
|
||||
+ skip "SM2 is not supported by this OpenSSL build", 4
|
||||
if disabled("sm2");
|
||||
ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
|
||||
"-new", "-key", srctop_file("test", "certs", "sm2.key"),
|
||||
@@ -197,6 +197,17 @@ subtest "generating SM2 certificate requests" => sub {
|
||||
"-verify", "-in", "testreq.pem", "-noout",
|
||||
"-sm2-id", "1234567812345678", "-sm3"])),
|
||||
"Verifying signature on SM2 certificate request");
|
||||
+
|
||||
+ ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
|
||||
+ "-new", "-key", srctop_file("test", "certs", "sm2.key"),
|
||||
+ "-sigopt", "sm2_hex_id:DEADBEEF",
|
||||
+ "-out", "testreq.pem", "-sm3"])),
|
||||
+ "Generating SM2 certificate request with hex id");
|
||||
+
|
||||
+ ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
|
||||
+ "-verify", "-in", "testreq.pem", "-noout",
|
||||
+ "-sm2-hex-id", "DEADBEEF", "-sm3"])),
|
||||
+ "Verifying signature on SM2 certificate request");
|
||||
}
|
||||
};
|
||||
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,482 @@
|
||||
From b14bf717ccb166cce13173a817106effb02f6c2e Mon Sep 17 00:00:00 2001
|
||||
From: Paul Yang <yang.yang@baishancloud.com>
|
||||
Date: Wed, 16 Jan 2019 16:16:28 +0800
|
||||
Subject: [PATCH 01/15] Support raw input data in apps/pkeyutl
|
||||
|
||||
Some signature algorithms require special treatment for digesting, such
|
||||
as SM2. This patch adds the ability of handling raw input data in
|
||||
apps/pkeyutl other than accepting only pre-hashed input data.
|
||||
|
||||
Beside, SM2 requries an ID string when signing or verifying a piece of data,
|
||||
this patch also adds the ability for apps/pkeyutil to specify that ID
|
||||
string.
|
||||
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/8186)
|
||||
---
|
||||
apps/pkeyutl.c | 168 +++++++++++++++++++++++++++++----
|
||||
crypto/sm2/sm2_pmeth.c | 3 +
|
||||
doc/man1/pkeyutl.pod | 45 +++++++++
|
||||
test/certs/sm2.crt | 13 +++
|
||||
test/certs/sm2.key | 5 +
|
||||
test/recipes/20-test_pkeyutl.t | 43 +++++++++
|
||||
6 files changed, 260 insertions(+), 17 deletions(-)
|
||||
create mode 100644 test/certs/sm2.crt
|
||||
create mode 100644 test/certs/sm2.key
|
||||
create mode 100644 test/recipes/20-test_pkeyutl.t
|
||||
|
||||
diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c
|
||||
index 831e14d..bca0464 100644
|
||||
--- a/apps/pkeyutl.c
|
||||
+++ b/apps/pkeyutl.c
|
||||
@@ -22,7 +22,7 @@
|
||||
static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||
const char *keyfile, int keyform, int key_type,
|
||||
char *passinarg, int pkey_op, ENGINE *e,
|
||||
- const int impl);
|
||||
+ const int impl, EVP_PKEY **ppkey);
|
||||
|
||||
static int setup_peer(EVP_PKEY_CTX *ctx, int peerform, const char *file,
|
||||
ENGINE *e);
|
||||
@@ -31,6 +31,11 @@ static int do_keyop(EVP_PKEY_CTX *ctx, int pkey_op,
|
||||
unsigned char *out, size_t *poutlen,
|
||||
const unsigned char *in, size_t inlen);
|
||||
|
||||
+static int do_raw_keyop(int pkey_op, EVP_PKEY_CTX *ctx,
|
||||
+ const EVP_MD *md, EVP_PKEY *pkey, BIO *in,
|
||||
+ unsigned char *sig, int siglen,
|
||||
+ unsigned char **out, size_t *poutlen);
|
||||
+
|
||||
typedef enum OPTION_choice {
|
||||
OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
|
||||
OPT_ENGINE, OPT_ENGINE_IMPL, OPT_IN, OPT_OUT,
|
||||
@@ -38,12 +43,15 @@ typedef enum OPTION_choice {
|
||||
OPT_VERIFY, OPT_VERIFYRECOVER, OPT_REV, OPT_ENCRYPT, OPT_DECRYPT,
|
||||
OPT_DERIVE, OPT_SIGFILE, OPT_INKEY, OPT_PEERKEY, OPT_PASSIN,
|
||||
OPT_PEERFORM, OPT_KEYFORM, OPT_PKEYOPT, OPT_KDF, OPT_KDFLEN,
|
||||
- OPT_R_ENUM
|
||||
+ OPT_R_ENUM, OPT_RAWIN, OPT_DIGEST
|
||||
} OPTION_CHOICE;
|
||||
|
||||
const OPTIONS pkeyutl_options[] = {
|
||||
{"help", OPT_HELP, '-', "Display this summary"},
|
||||
{"in", OPT_IN, '<', "Input file - default stdin"},
|
||||
+ {"rawin", OPT_RAWIN, '-', "Indicate the input data is in raw form"},
|
||||
+ {"digest", OPT_DIGEST, 's',
|
||||
+ "Specify the digest algorithm when signing the raw input data"},
|
||||
{"out", OPT_OUT, '>', "Output file - default stdout"},
|
||||
{"pubin", OPT_PUBIN, '-', "Input is a public key"},
|
||||
{"certin", OPT_CERTIN, '-', "Input is a cert with a public key"},
|
||||
@@ -80,6 +88,7 @@ int pkeyutl_main(int argc, char **argv)
|
||||
BIO *in = NULL, *out = NULL;
|
||||
ENGINE *e = NULL;
|
||||
EVP_PKEY_CTX *ctx = NULL;
|
||||
+ EVP_PKEY *pkey = NULL;
|
||||
char *infile = NULL, *outfile = NULL, *sigfile = NULL, *passinarg = NULL;
|
||||
char hexdump = 0, asn1parse = 0, rev = 0, *prog;
|
||||
unsigned char *buf_in = NULL, *buf_out = NULL, *sig = NULL;
|
||||
@@ -94,6 +103,8 @@ int pkeyutl_main(int argc, char **argv)
|
||||
const char *kdfalg = NULL;
|
||||
int kdflen = 0;
|
||||
STACK_OF(OPENSSL_STRING) *pkeyopts = NULL;
|
||||
+ int rawin = 0;
|
||||
+ const EVP_MD *md = NULL;
|
||||
|
||||
prog = opt_init(argc, argv, pkeyutl_options);
|
||||
while ((o = opt_next()) != OPT_EOF) {
|
||||
@@ -192,12 +203,39 @@ int pkeyutl_main(int argc, char **argv)
|
||||
goto end;
|
||||
}
|
||||
break;
|
||||
+ case OPT_RAWIN:
|
||||
+ rawin = 1;
|
||||
+ break;
|
||||
+ case OPT_DIGEST:
|
||||
+ if (!opt_md(opt_arg(), &md))
|
||||
+ goto end;
|
||||
+ break;
|
||||
}
|
||||
}
|
||||
argc = opt_num_rest();
|
||||
if (argc != 0)
|
||||
goto opthelp;
|
||||
|
||||
+ if (rawin && pkey_op != EVP_PKEY_OP_SIGN && pkey_op != EVP_PKEY_OP_VERIFY) {
|
||||
+ BIO_printf(bio_err,
|
||||
+ "%s: -rawin can only be used with -sign or -verify\n",
|
||||
+ prog);
|
||||
+ goto opthelp;
|
||||
+ }
|
||||
+
|
||||
+ if (md != NULL && !rawin) {
|
||||
+ BIO_printf(bio_err,
|
||||
+ "%s: -digest can only be used with -rawin\n",
|
||||
+ prog);
|
||||
+ goto opthelp;
|
||||
+ }
|
||||
+
|
||||
+ if (rawin && rev) {
|
||||
+ BIO_printf(bio_err, "%s: -rev cannot be used with raw input\n",
|
||||
+ prog);
|
||||
+ goto opthelp;
|
||||
+ }
|
||||
+
|
||||
if (kdfalg != NULL) {
|
||||
if (kdflen == 0) {
|
||||
BIO_printf(bio_err,
|
||||
@@ -214,7 +252,7 @@ int pkeyutl_main(int argc, char **argv)
|
||||
goto opthelp;
|
||||
}
|
||||
ctx = init_ctx(kdfalg, &keysize, inkey, keyform, key_type,
|
||||
- passinarg, pkey_op, e, engine_impl);
|
||||
+ passinarg, pkey_op, e, engine_impl, &pkey);
|
||||
if (ctx == NULL) {
|
||||
BIO_printf(bio_err, "%s: Error initializing context\n", prog);
|
||||
ERR_print_errors(bio_err);
|
||||
@@ -277,7 +315,8 @@ int pkeyutl_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
- if (in != NULL) {
|
||||
+ /* Raw input data is handled elsewhere */
|
||||
+ if (in != NULL && !rawin) {
|
||||
/* Read the input data */
|
||||
buf_inlen = bio_to_mem(&buf_in, keysize * 10, in);
|
||||
if (buf_inlen < 0) {
|
||||
@@ -296,8 +335,9 @@ int pkeyutl_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
- /* Sanity check the input */
|
||||
- if (buf_inlen > EVP_MAX_MD_SIZE
|
||||
+ /* Sanity check the input if the input is not raw */
|
||||
+ if (!rawin
|
||||
+ && buf_inlen > EVP_MAX_MD_SIZE
|
||||
&& (pkey_op == EVP_PKEY_OP_SIGN
|
||||
|| pkey_op == EVP_PKEY_OP_VERIFY)) {
|
||||
BIO_printf(bio_err,
|
||||
@@ -306,8 +346,13 @@ int pkeyutl_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (pkey_op == EVP_PKEY_OP_VERIFY) {
|
||||
- rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen,
|
||||
- buf_in, (size_t)buf_inlen);
|
||||
+ if (rawin) {
|
||||
+ rv = do_raw_keyop(pkey_op, ctx, md, pkey, in, sig, siglen,
|
||||
+ NULL, 0);
|
||||
+ } else {
|
||||
+ rv = EVP_PKEY_verify(ctx, sig, (size_t)siglen,
|
||||
+ buf_in, (size_t)buf_inlen);
|
||||
+ }
|
||||
if (rv == 1) {
|
||||
BIO_puts(out, "Signature Verified Successfully\n");
|
||||
ret = 0;
|
||||
@@ -320,14 +365,20 @@ int pkeyutl_main(int argc, char **argv)
|
||||
buf_outlen = kdflen;
|
||||
rv = 1;
|
||||
} else {
|
||||
- rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,
|
||||
- buf_in, (size_t)buf_inlen);
|
||||
- }
|
||||
- if (rv > 0 && buf_outlen != 0) {
|
||||
- buf_out = app_malloc(buf_outlen, "buffer output");
|
||||
- rv = do_keyop(ctx, pkey_op,
|
||||
- buf_out, (size_t *)&buf_outlen,
|
||||
- buf_in, (size_t)buf_inlen);
|
||||
+ if (rawin) {
|
||||
+ /* rawin allocates the buffer in do_raw_keyop() */
|
||||
+ rv = do_raw_keyop(pkey_op, ctx, md, pkey, in, NULL, 0,
|
||||
+ &buf_out, (size_t *)&buf_outlen);
|
||||
+ } else {
|
||||
+ rv = do_keyop(ctx, pkey_op, NULL, (size_t *)&buf_outlen,
|
||||
+ buf_in, (size_t)buf_inlen);
|
||||
+ if (rv > 0 && buf_outlen != 0) {
|
||||
+ buf_out = app_malloc(buf_outlen, "buffer output");
|
||||
+ rv = do_keyop(ctx, pkey_op,
|
||||
+ buf_out, (size_t *)&buf_outlen,
|
||||
+ buf_in, (size_t)buf_inlen);
|
||||
+ }
|
||||
+ }
|
||||
}
|
||||
if (rv <= 0) {
|
||||
if (pkey_op != EVP_PKEY_OP_DERIVE) {
|
||||
@@ -364,7 +415,7 @@ int pkeyutl_main(int argc, char **argv)
|
||||
static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||
const char *keyfile, int keyform, int key_type,
|
||||
char *passinarg, int pkey_op, ENGINE *e,
|
||||
- const int engine_impl)
|
||||
+ const int engine_impl, EVP_PKEY **ppkey)
|
||||
{
|
||||
EVP_PKEY *pkey = NULL;
|
||||
EVP_PKEY_CTX *ctx = NULL;
|
||||
@@ -422,10 +473,25 @@ static EVP_PKEY_CTX *init_ctx(const char *kdfalg, int *pkeysize,
|
||||
}
|
||||
ctx = EVP_PKEY_CTX_new_id(kdfnid, impl);
|
||||
} else {
|
||||
+ EC_KEY *eckey = NULL;
|
||||
+ const EC_GROUP *group = NULL;
|
||||
+ int nid;
|
||||
+
|
||||
if (pkey == NULL)
|
||||
goto end;
|
||||
+ /* SM2 needs a special treatment */
|
||||
+ if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
|
||||
+ if ((eckey = EVP_PKEY_get0_EC_KEY(pkey)) == NULL
|
||||
+ || (group = EC_KEY_get0_group(eckey)) == NULL
|
||||
+ || (nid = EC_GROUP_get_curve_name(group)) == 0)
|
||||
+ goto end;
|
||||
+ if (nid == NID_sm2)
|
||||
+ EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2);
|
||||
+ }
|
||||
*pkeysize = EVP_PKEY_size(pkey);
|
||||
ctx = EVP_PKEY_CTX_new(pkey, impl);
|
||||
+ if (ppkey != NULL)
|
||||
+ *ppkey = pkey;
|
||||
EVP_PKEY_free(pkey);
|
||||
}
|
||||
|
||||
@@ -522,3 +588,71 @@ static int do_keyop(EVP_PKEY_CTX *ctx, int pkey_op,
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
+
|
||||
+#define TBUF_MAXSIZE 2048
|
||||
+
|
||||
+static int do_raw_keyop(int pkey_op, EVP_PKEY_CTX *ctx,
|
||||
+ const EVP_MD *md, EVP_PKEY *pkey, BIO *in,
|
||||
+ unsigned char *sig, int siglen,
|
||||
+ unsigned char **out, size_t *poutlen)
|
||||
+{
|
||||
+ int rv = 0;
|
||||
+ EVP_MD_CTX *mctx = NULL;
|
||||
+ unsigned char tbuf[TBUF_MAXSIZE];
|
||||
+ int tbuf_len = 0;
|
||||
+
|
||||
+ if ((mctx = EVP_MD_CTX_new()) == NULL) {
|
||||
+ BIO_printf(bio_err, "Error: out of memory\n");
|
||||
+ return rv;
|
||||
+ }
|
||||
+ EVP_MD_CTX_set_pkey_ctx(mctx, ctx);
|
||||
+
|
||||
+ switch(pkey_op) {
|
||||
+ case EVP_PKEY_OP_VERIFY:
|
||||
+ if (EVP_DigestVerifyInit(mctx, NULL, md, NULL, pkey) != 1)
|
||||
+ goto end;
|
||||
+ for (;;) {
|
||||
+ tbuf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);
|
||||
+ if (tbuf_len == 0)
|
||||
+ break;
|
||||
+ if (tbuf_len < 0) {
|
||||
+ BIO_printf(bio_err, "Error reading raw input data\n");
|
||||
+ goto end;
|
||||
+ }
|
||||
+ rv = EVP_DigestVerifyUpdate(mctx, tbuf, (size_t)tbuf_len);
|
||||
+ if (rv != 1) {
|
||||
+ BIO_printf(bio_err, "Error verifying raw input data\n");
|
||||
+ goto end;
|
||||
+ }
|
||||
+ }
|
||||
+ rv = EVP_DigestVerifyFinal(mctx, sig, (size_t)siglen);
|
||||
+ break;
|
||||
+ case EVP_PKEY_OP_SIGN:
|
||||
+ if (EVP_DigestSignInit(mctx, NULL, md, NULL, pkey) != 1)
|
||||
+ goto end;
|
||||
+ for (;;) {
|
||||
+ tbuf_len = BIO_read(in, tbuf, TBUF_MAXSIZE);
|
||||
+ if (tbuf_len == 0)
|
||||
+ break;
|
||||
+ if (tbuf_len < 0) {
|
||||
+ BIO_printf(bio_err, "Error reading raw input data\n");
|
||||
+ goto end;
|
||||
+ }
|
||||
+ rv = EVP_DigestSignUpdate(mctx, tbuf, (size_t)tbuf_len);
|
||||
+ if (rv != 1) {
|
||||
+ BIO_printf(bio_err, "Error signing raw input data\n");
|
||||
+ goto end;
|
||||
+ }
|
||||
+ }
|
||||
+ rv = EVP_DigestSignFinal(mctx, NULL, poutlen);
|
||||
+ if (rv == 1 && out != NULL) {
|
||||
+ *out = app_malloc(*poutlen, "buffer output");
|
||||
+ rv = EVP_DigestSignFinal(mctx, *out, poutlen);
|
||||
+ }
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ end:
|
||||
+ EVP_MD_CTX_free(mctx);
|
||||
+ return rv;
|
||||
+}
|
||||
diff --git a/crypto/sm2/sm2_pmeth.c b/crypto/sm2/sm2_pmeth.c
|
||||
index 0e722b9..837bdc1 100644
|
||||
--- a/crypto/sm2/sm2_pmeth.c
|
||||
+++ b/crypto/sm2/sm2_pmeth.c
|
||||
@@ -252,6 +252,9 @@ static int pkey_sm2_ctrl_str(EVP_PKEY_CTX *ctx,
|
||||
else
|
||||
return -2;
|
||||
return EVP_PKEY_CTX_set_ec_param_enc(ctx, param_enc);
|
||||
+ } else if (strcmp(type, "sm2_id") == 0) {
|
||||
+ return pkey_sm2_ctrl(ctx, EVP_PKEY_CTRL_SET1_ID,
|
||||
+ (int)strlen(value), (void *)value);
|
||||
}
|
||||
|
||||
return -2;
|
||||
diff --git a/doc/man1/pkeyutl.pod b/doc/man1/pkeyutl.pod
|
||||
index f6fd48d..f0f80af 100644
|
||||
--- a/doc/man1/pkeyutl.pod
|
||||
+++ b/doc/man1/pkeyutl.pod
|
||||
@@ -10,6 +10,8 @@ pkeyutl - public key algorithm utility
|
||||
B<openssl> B<pkeyutl>
|
||||
[B<-help>]
|
||||
[B<-in file>]
|
||||
+[B<-rawin>]
|
||||
+[B<-digest algorithm>]
|
||||
[B<-out file>]
|
||||
[B<-sigfile file>]
|
||||
[B<-inkey file>]
|
||||
@@ -54,6 +56,23 @@ Print out a usage message.
|
||||
This specifies the input filename to read data from or standard input
|
||||
if this option is not specified.
|
||||
|
||||
+=item B<-rawin>
|
||||
+
|
||||
+This indicates that the input data is raw data, which is not hashed by any
|
||||
+message digest algorithm. The user can specify a digest algorithm by using
|
||||
+the B<-digest> option. This option can only be used with B<-sign> and
|
||||
+B<-verify>.
|
||||
+
|
||||
+=item B<-digest algorithm>
|
||||
+
|
||||
+This specifies the digest algorithm which is used to hash the input data before
|
||||
+signing or verifying it with the input key. This option could be omitted if the
|
||||
+signature algorithm does not require one (for instance, EdDSA). If this option
|
||||
+is omitted but the signature algorithm requires one, a default value will be
|
||||
+used. For signature algorithms like RSA, DSA and ECDSA, SHA-256 will be the
|
||||
+default digest algorithm. For SM2, it will be SM3. If this option is present,
|
||||
+then the B<-rawin> option must be also specified to B<pkeyutl>.
|
||||
+
|
||||
=item B<-out filename>
|
||||
|
||||
Specifies the output filename to write to or standard output by
|
||||
@@ -296,6 +315,22 @@ the B<-pkeyopt> B<digest> option.
|
||||
The X25519 and X448 algorithms support key derivation only. Currently there are
|
||||
no additional options.
|
||||
|
||||
+=head1 SM2
|
||||
+
|
||||
+The SM2 algorithm supports sign, verify, encrypt and decrypt operations. For
|
||||
+the sign and verify operations, SM2 requires an ID string to be passed in. The
|
||||
+following B<pkeyopt> value is supported:
|
||||
+
|
||||
+=over 4
|
||||
+
|
||||
+=item B<sm2_id:string>
|
||||
+
|
||||
+This sets the ID string used in SM2 sign or verify operations. While verifying
|
||||
+an SM2 signature, the ID string must be the same one used when signing the data.
|
||||
+Otherwise the verification will fail.
|
||||
+
|
||||
+=back
|
||||
+
|
||||
=head1 EXAMPLES
|
||||
|
||||
Sign some data using a private key:
|
||||
@@ -329,6 +364,16 @@ Decrypt some data using a private key with OAEP padding using SHA256:
|
||||
openssl pkeyutl -decrypt -in file -inkey key.pem -out secret \
|
||||
-pkeyopt rsa_padding_mode:oaep -pkeyopt rsa_oaep_md:sha256
|
||||
|
||||
+Sign some data using an L<SM2(7)> private key and a specific ID:
|
||||
+
|
||||
+ openssl pkeyutl -sign -in file -inkey sm2.key -out sig -rawin -digest sm3 \
|
||||
+ -pkeyopt sm2_id:someid
|
||||
+
|
||||
+Verify some data using an L<SM2(7)> certificate and a specific ID:
|
||||
+
|
||||
+ openssl pkeyutl -verify -certin -in file -inkey sm2.cert -sigfile sig \
|
||||
+ -rawin -digest sm3 -pkeyopt sm2_id:someid
|
||||
+
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<genpkey(1)>, L<pkey(1)>, L<rsautl(1)>
|
||||
diff --git a/test/certs/sm2.crt b/test/certs/sm2.crt
|
||||
new file mode 100644
|
||||
index 0000000..189abb1
|
||||
--- /dev/null
|
||||
+++ b/test/certs/sm2.crt
|
||||
@@ -0,0 +1,13 @@
|
||||
+-----BEGIN CERTIFICATE-----
|
||||
+MIIB6DCCAY6gAwIBAgIJAKH2BR6ITHZeMAoGCCqBHM9VAYN1MGgxCzAJBgNVBAYT
|
||||
+AkNOMQswCQYDVQQIDAJMTjERMA8GA1UEBwwIU2hlbnlhbmcxETAPBgNVBAoMCFRl
|
||||
+c3QgT3JnMRAwDgYDVQQLDAdUZXN0IE9VMRQwEgYDVQQDDAtUZXN0IFNNMiBDQTAe
|
||||
+Fw0xOTAyMTkwNzA1NDhaFw0yMzAzMzAwNzA1NDhaMG8xCzAJBgNVBAYTAkNOMQsw
|
||||
+CQYDVQQIDAJMTjERMA8GA1UEBwwIU2hlbnlhbmcxETAPBgNVBAoMCFRlc3QgT3Jn
|
||||
+MRAwDgYDVQQLDAdUZXN0IE9VMRswGQYDVQQDDBJUZXN0IFNNMiBTaWduIENlcnQw
|
||||
+WTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAAQwqeNkWp7fiu1KZnuDkAucpM8piEzE
|
||||
+TL1ymrcrOBvv8mhNNkeb20asbWgFQI2zOrSM99/sXGn9rM2/usM/MlcaoxowGDAJ
|
||||
+BgNVHRMEAjAAMAsGA1UdDwQEAwIGwDAKBggqgRzPVQGDdQNIADBFAiEA9edBnAqT
|
||||
+TNuGIUIvXsj6/nP+AzXA9HGtAIY4nrqW8LkCIHyZzhRTlxYtgfqkDl0OK5QQRCZH
|
||||
+OZOfmtx613VyzXwc
|
||||
+-----END CERTIFICATE-----
|
||||
diff --git a/test/certs/sm2.key b/test/certs/sm2.key
|
||||
new file mode 100644
|
||||
index 0000000..1efd364
|
||||
--- /dev/null
|
||||
+++ b/test/certs/sm2.key
|
||||
@@ -0,0 +1,5 @@
|
||||
+-----BEGIN PRIVATE KEY-----
|
||||
+MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQgSKhk+4xGyDI+IS2H
|
||||
+WVfFPDxh1qv5+wtrddaIsGNXGZihRANCAAQwqeNkWp7fiu1KZnuDkAucpM8piEzE
|
||||
+TL1ymrcrOBvv8mhNNkeb20asbWgFQI2zOrSM99/sXGn9rM2/usM/Mlca
|
||||
+-----END PRIVATE KEY-----
|
||||
diff --git a/test/recipes/20-test_pkeyutl.t b/test/recipes/20-test_pkeyutl.t
|
||||
new file mode 100644
|
||||
index 0000000..a051138
|
||||
--- /dev/null
|
||||
+++ b/test/recipes/20-test_pkeyutl.t
|
||||
@@ -0,0 +1,43 @@
|
||||
+#! /usr/bin/env perl
|
||||
+# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+#
|
||||
+# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
+# this file except in compliance with the License. You can obtain a copy
|
||||
+# in the file LICENSE in the source distribution or at
|
||||
+# https://www.openssl.org/source/license.html
|
||||
+
|
||||
+use strict;
|
||||
+use warnings;
|
||||
+
|
||||
+use File::Spec;
|
||||
+use OpenSSL::Test qw/:DEFAULT srctop_file/;
|
||||
+use OpenSSL::Test::Utils;
|
||||
+
|
||||
+setup("test_pkeyutl");
|
||||
+
|
||||
+plan tests => 2;
|
||||
+
|
||||
+sub sign
|
||||
+{
|
||||
+ # Utilize the sm2.crt as the TBS file
|
||||
+ return run(app(([ 'openssl', 'pkeyutl', '-sign',
|
||||
+ '-in', srctop_file('test', 'certs', 'sm2.crt'),
|
||||
+ '-inkey', srctop_file('test', 'certs', 'sm2.key'),
|
||||
+ '-out', 'signature.sm2', '-rawin',
|
||||
+ '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
|
||||
+}
|
||||
+
|
||||
+sub verify
|
||||
+{
|
||||
+ # Utilize the sm2.crt as the TBS file
|
||||
+ return run(app(([ 'openssl', 'pkeyutl', '-verify', '-certin',
|
||||
+ '-in', srctop_file('test', 'certs', 'sm2.crt'),
|
||||
+ '-inkey', srctop_file('test', 'certs', 'sm2.crt'),
|
||||
+ '-sigfile', 'signature.sm2', '-rawin',
|
||||
+ '-digest', 'sm3', '-pkeyopt', 'sm2_id:someid'])));
|
||||
+}
|
||||
+
|
||||
+ok(sign, "Sign a piece of data using SM2");
|
||||
+ok(verify, "Verify an SM2 signature against a piece of data");
|
||||
+
|
||||
+unlink 'signature.sm2';
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
@ -0,0 +1,58 @@
|
||||
From 3ef5c3034e5c545f34d6929568f3f2b10ac4bdf0 Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Mraz <tomas@openssl.org>
|
||||
Date: Mon, 28 Feb 2022 18:26:35 +0100
|
||||
Subject: [PATCH] Add a negative testcase for BN_mod_sqrt
|
||||
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
---
|
||||
test/bntest.c | 11 ++++++++++-
|
||||
test/recipes/10-test_bn_data/bnmod.txt | 12 ++++++++++++
|
||||
2 files changed, 22 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/test/bntest.c b/test/bntest.c
|
||||
index 390dd80073..1cab660bca 100644
|
||||
--- a/test/bntest.c
|
||||
+++ b/test/bntest.c
|
||||
@@ -1729,8 +1729,17 @@ static int file_modsqrt(STANZA *s)
|
||||
|| !TEST_ptr(ret2 = BN_new()))
|
||||
goto err;
|
||||
|
||||
+ if (BN_is_negative(mod_sqrt)) {
|
||||
+ /* A negative testcase */
|
||||
+ if (!TEST_ptr_null(BN_mod_sqrt(ret, a, p, ctx)))
|
||||
+ goto err;
|
||||
+
|
||||
+ st = 1;
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
/* There are two possible answers. */
|
||||
- if (!TEST_true(BN_mod_sqrt(ret, a, p, ctx))
|
||||
+ if (!TEST_ptr(BN_mod_sqrt(ret, a, p, ctx))
|
||||
|| !TEST_true(BN_sub(ret2, p, ret)))
|
||||
goto err;
|
||||
|
||||
diff --git a/test/recipes/10-test_bn_data/bnmod.txt b/test/recipes/10-test_bn_data/bnmod.txt
|
||||
index 5ea4d031f2..e28cc6bfb0 100644
|
||||
--- a/test/recipes/10-test_bn_data/bnmod.txt
|
||||
+++ b/test/recipes/10-test_bn_data/bnmod.txt
|
||||
@@ -2799,3 +2799,15 @@ P = 9df9d6cc20b8540411af4e5357ef2b0353cb1f2ab5ffc3e246b41c32f71e951f
|
||||
ModSqrt = a1d52989f12f204d3d2167d9b1e6c8a6174c0c786a979a5952383b7b8bd186
|
||||
A = 2eee37cf06228a387788188e650bc6d8a2ff402931443f69156a29155eca07dcb45f3aac238d92943c0c25c896098716baa433f25bd696a142f5a69d5d937e81
|
||||
P = 9df9d6cc20b8540411af4e5357ef2b0353cb1f2ab5ffc3e246b41c32f71e951f
|
||||
+
|
||||
+# Negative testcases for BN_mod_sqrt()
|
||||
+
|
||||
+# This one triggers an infinite loop with unfixed implementation
|
||||
+# It should just fail.
|
||||
+ModSqrt = -1
|
||||
+A = 20a7ee
|
||||
+P = 460201
|
||||
+
|
||||
+ModSqrt = -1
|
||||
+A = 65bebdb00a96fc814ec44b81f98b59fba3c30203928fa5214c51e0a97091645280c947b005847f239758482b9bfc45b066fde340d1fe32fc9c1bf02e1b2d0ed
|
||||
+P = 9df9d6cc20b8540411af4e5357ef2b0353cb1f2ab5ffc3e246b41c32f71e951f
|
||||
--
|
||||
2.27.0
|
||||
|
@ -0,0 +1,69 @@
|
||||
From 3118eb64934499d93db3230748a452351d1d9a65 Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Mraz <tomas@openssl.org>
|
||||
Date: Mon, 28 Feb 2022 18:26:21 +0100
|
||||
Subject: [PATCH] Fix possible infinite loop in BN_mod_sqrt()
|
||||
|
||||
The calculation in some cases does not finish for non-prime p.
|
||||
|
||||
This fixes CVE-2022-0778.
|
||||
|
||||
Based on patch by David Benjamin <davidben@google.com>.
|
||||
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
---
|
||||
crypto/bn/bn_sqrt.c | 30 ++++++++++++++++++------------
|
||||
1 file changed, 18 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/crypto/bn/bn_sqrt.c b/crypto/bn/bn_sqrt.c
|
||||
index 1723d5ded5..53b0f55985 100644
|
||||
--- a/crypto/bn/bn_sqrt.c
|
||||
+++ b/crypto/bn/bn_sqrt.c
|
||||
@@ -14,7 +14,8 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
|
||||
/*
|
||||
* Returns 'ret' such that ret^2 == a (mod p), using the Tonelli/Shanks
|
||||
* algorithm (cf. Henri Cohen, "A Course in Algebraic Computational Number
|
||||
- * Theory", algorithm 1.5.1). 'p' must be prime!
|
||||
+ * Theory", algorithm 1.5.1). 'p' must be prime, otherwise an error or
|
||||
+ * an incorrect "result" will be returned.
|
||||
*/
|
||||
{
|
||||
BIGNUM *ret = in;
|
||||
@@ -301,18 +302,23 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
|
||||
goto vrfy;
|
||||
}
|
||||
|
||||
- /* find smallest i such that b^(2^i) = 1 */
|
||||
- i = 1;
|
||||
- if (!BN_mod_sqr(t, b, p, ctx))
|
||||
- goto end;
|
||||
- while (!BN_is_one(t)) {
|
||||
- i++;
|
||||
- if (i == e) {
|
||||
- BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
|
||||
- goto end;
|
||||
+ /* Find the smallest i, 0 < i < e, such that b^(2^i) = 1. */
|
||||
+ for (i = 1; i < e; i++) {
|
||||
+ if (i == 1) {
|
||||
+ if (!BN_mod_sqr(t, b, p, ctx))
|
||||
+ goto end;
|
||||
+
|
||||
+ } else {
|
||||
+ if (!BN_mod_mul(t, t, t, p, ctx))
|
||||
+ goto end;
|
||||
}
|
||||
- if (!BN_mod_mul(t, t, t, p, ctx))
|
||||
- goto end;
|
||||
+ if (BN_is_one(t))
|
||||
+ break;
|
||||
+ }
|
||||
+ /* If not found, a is not a square or p is not prime. */
|
||||
+ if (i >= e) {
|
||||
+ BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
|
||||
+ goto end;
|
||||
}
|
||||
|
||||
/* t := y^2^(e - i - 1) */
|
||||
--
|
||||
2.27.0
|
||||
|
76
dependency/openssl/CVE-2022-1292.patch
Normal file
76
dependency/openssl/CVE-2022-1292.patch
Normal file
@ -0,0 +1,76 @@
|
||||
From e5fd1728ef4c7a5bf7c7a7163ca60370460a6e23 Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Mraz <tomas@openssl.org>
|
||||
Date: Tue, 26 Apr 2022 12:40:24 +0200
|
||||
Subject: [PATCH] c_rehash: Do not use shell to invoke openssl
|
||||
|
||||
Except on VMS where it is safe.
|
||||
|
||||
This fixes CVE-2022-1292.
|
||||
|
||||
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
---
|
||||
tools/c_rehash.in | 29 +++++++++++++++++++++++++----
|
||||
1 file changed, 25 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/tools/c_rehash.in b/tools/c_rehash.in
|
||||
index fa7c6c9..83c1cc8 100644
|
||||
--- a/tools/c_rehash.in
|
||||
+++ b/tools/c_rehash.in
|
||||
@@ -152,6 +152,23 @@ sub check_file {
|
||||
return ($is_cert, $is_crl);
|
||||
}
|
||||
|
||||
+sub compute_hash {
|
||||
+ my $fh;
|
||||
+ if ( $^O eq "VMS" ) {
|
||||
+ # VMS uses the open through shell
|
||||
+ # The file names are safe there and list form is unsupported
|
||||
+ if (!open($fh, "-|", join(' ', @_))) {
|
||||
+ print STDERR "Cannot compute hash on '$fname'\n";
|
||||
+ return;
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (!open($fh, "-|", @_)) {
|
||||
+ print STDERR "Cannot compute hash on '$fname'\n";
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ return (<$fh>, <$fh>);
|
||||
+}
|
||||
|
||||
# Link a certificate to its subject name hash value, each hash is of
|
||||
# the form <hash>.<n> where n is an integer. If the hash value already exists
|
||||
@@ -161,10 +178,12 @@ sub check_file {
|
||||
|
||||
sub link_hash_cert {
|
||||
my $fname = $_[0];
|
||||
- $fname =~ s/\"/\\\"/g;
|
||||
- my ($hash, $fprint) = `"$openssl" x509 $x509hash -fingerprint -noout -in "$fname"`;
|
||||
+ my ($hash, $fprint) = compute_hash($openssl, "x509", $x509hash,
|
||||
+ "-fingerprint", "-noout",
|
||||
+ "-in", $fname);
|
||||
chomp $hash;
|
||||
chomp $fprint;
|
||||
+ return if !$hash;
|
||||
$fprint =~ s/^.*=//;
|
||||
$fprint =~ tr/://d;
|
||||
my $suffix = 0;
|
||||
@@ -202,10 +221,12 @@ sub link_hash_cert {
|
||||
|
||||
sub link_hash_crl {
|
||||
my $fname = $_[0];
|
||||
- $fname =~ s/'/'\\''/g;
|
||||
- my ($hash, $fprint) = `"$openssl" crl $crlhash -fingerprint -noout -in '$fname'`;
|
||||
+ my ($hash, $fprint) = compute_hash($openssl, "crl", $crlhash,
|
||||
+ "-fingerprint", "-noout",
|
||||
+ "-in", $fname);
|
||||
chomp $hash;
|
||||
chomp $fprint;
|
||||
+ return if !$hash;
|
||||
$fprint =~ s/^.*=//;
|
||||
$fprint =~ tr/://d;
|
||||
my $suffix = 0;
|
||||
--
|
||||
1.8.3.1
|
||||
|
@ -0,0 +1,257 @@
|
||||
From 9639817dac8bbbaa64d09efad7464ccc405527c7 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Fiala <daniel@openssl.org>
|
||||
Date: Sun, 29 May 2022 20:11:24 +0200
|
||||
Subject: [PATCH] Fix file operations in c_rehash.
|
||||
|
||||
CVE-2022-2068
|
||||
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
Reviewed-by: Richard Levitte <levitte@openssl.org>
|
||||
---
|
||||
tools/c_rehash.in | 216 +++++++++++++++++++++++++++---------------------------
|
||||
1 file changed, 107 insertions(+), 109 deletions(-)
|
||||
|
||||
diff --git a/tools/c_rehash.in b/tools/c_rehash.in
|
||||
index cfd18f5..9d2a6f6 100644
|
||||
--- a/tools/c_rehash.in
|
||||
+++ b/tools/c_rehash.in
|
||||
@@ -104,52 +104,78 @@ foreach (@dirlist) {
|
||||
}
|
||||
exit($errorcount);
|
||||
|
||||
+sub copy_file {
|
||||
+ my ($src_fname, $dst_fname) = @_;
|
||||
+
|
||||
+ if (open(my $in, "<", $src_fname)) {
|
||||
+ if (open(my $out, ">", $dst_fname)) {
|
||||
+ print $out $_ while (<$in>);
|
||||
+ close $out;
|
||||
+ } else {
|
||||
+ warn "Cannot open $dst_fname for write, $!";
|
||||
+ }
|
||||
+ close $in;
|
||||
+ } else {
|
||||
+ warn "Cannot open $src_fname for read, $!";
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
sub hash_dir {
|
||||
- my %hashlist;
|
||||
- print "Doing $_[0]\n";
|
||||
- chdir $_[0];
|
||||
- opendir(DIR, ".");
|
||||
- my @flist = sort readdir(DIR);
|
||||
- closedir DIR;
|
||||
- if ( $removelinks ) {
|
||||
- # Delete any existing symbolic links
|
||||
- foreach (grep {/^[\da-f]+\.r{0,1}\d+$/} @flist) {
|
||||
- if (-l $_) {
|
||||
- print "unlink $_" if $verbose;
|
||||
- unlink $_ || warn "Can't unlink $_, $!\n";
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
- FILE: foreach $fname (grep {/\.(pem)|(crt)|(cer)|(crl)$/} @flist) {
|
||||
- # Check to see if certificates and/or CRLs present.
|
||||
- my ($cert, $crl) = check_file($fname);
|
||||
- if (!$cert && !$crl) {
|
||||
- print STDERR "WARNING: $fname does not contain a certificate or CRL: skipping\n";
|
||||
- next;
|
||||
- }
|
||||
- link_hash_cert($fname) if ($cert);
|
||||
- link_hash_crl($fname) if ($crl);
|
||||
- }
|
||||
+ my $dir = shift;
|
||||
+ my %hashlist;
|
||||
+
|
||||
+ print "Doing $dir\n";
|
||||
+
|
||||
+ if (!chdir $dir) {
|
||||
+ print STDERR "WARNING: Cannot chdir to '$dir', $!\n";
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ opendir(DIR, ".") || print STDERR "WARNING: Cannot opendir '.', $!\n";
|
||||
+ my @flist = sort readdir(DIR);
|
||||
+ closedir DIR;
|
||||
+ if ( $removelinks ) {
|
||||
+ # Delete any existing symbolic links
|
||||
+ foreach (grep {/^[\da-f]+\.r{0,1}\d+$/} @flist) {
|
||||
+ if (-l $_) {
|
||||
+ print "unlink $_\n" if $verbose;
|
||||
+ unlink $_ || warn "Can't unlink $_, $!\n";
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ FILE: foreach $fname (grep {/\.(pem)|(crt)|(cer)|(crl)$/} @flist) {
|
||||
+ # Check to see if certificates and/or CRLs present.
|
||||
+ my ($cert, $crl) = check_file($fname);
|
||||
+ if (!$cert && !$crl) {
|
||||
+ print STDERR "WARNING: $fname does not contain a certificate or CRL: skipping\n";
|
||||
+ next;
|
||||
+ }
|
||||
+ link_hash_cert($fname) if ($cert);
|
||||
+ link_hash_crl($fname) if ($crl);
|
||||
+ }
|
||||
+
|
||||
+ chdir $pwd;
|
||||
}
|
||||
|
||||
sub check_file {
|
||||
- my ($is_cert, $is_crl) = (0,0);
|
||||
- my $fname = $_[0];
|
||||
- open IN, $fname;
|
||||
- while(<IN>) {
|
||||
- if (/^-----BEGIN (.*)-----/) {
|
||||
- my $hdr = $1;
|
||||
- if ($hdr =~ /^(X509 |TRUSTED |)CERTIFICATE$/) {
|
||||
- $is_cert = 1;
|
||||
- last if ($is_crl);
|
||||
- } elsif ($hdr eq "X509 CRL") {
|
||||
- $is_crl = 1;
|
||||
- last if ($is_cert);
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
- close IN;
|
||||
- return ($is_cert, $is_crl);
|
||||
+ my ($is_cert, $is_crl) = (0,0);
|
||||
+ my $fname = $_[0];
|
||||
+
|
||||
+ open(my $in, "<", $fname);
|
||||
+ while(<$in>) {
|
||||
+ if (/^-----BEGIN (.*)-----/) {
|
||||
+ my $hdr = $1;
|
||||
+ if ($hdr =~ /^(X509 |TRUSTED |)CERTIFICATE$/) {
|
||||
+ $is_cert = 1;
|
||||
+ last if ($is_crl);
|
||||
+ } elsif ($hdr eq "X509 CRL") {
|
||||
+ $is_crl = 1;
|
||||
+ last if ($is_cert);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ close $in;
|
||||
+ return ($is_cert, $is_crl);
|
||||
}
|
||||
|
||||
sub compute_hash {
|
||||
@@ -177,76 +203,48 @@ sub compute_hash {
|
||||
# certificate fingerprints
|
||||
|
||||
sub link_hash_cert {
|
||||
- my $fname = $_[0];
|
||||
- my ($hash, $fprint) = compute_hash($openssl, "x509", $x509hash,
|
||||
- "-fingerprint", "-noout",
|
||||
- "-in", $fname);
|
||||
- chomp $hash;
|
||||
- chomp $fprint;
|
||||
- return if !$hash;
|
||||
- $fprint =~ s/^.*=//;
|
||||
- $fprint =~ tr/://d;
|
||||
- my $suffix = 0;
|
||||
- # Search for an unused hash filename
|
||||
- while(exists $hashlist{"$hash.$suffix"}) {
|
||||
- # Hash matches: if fingerprint matches its a duplicate cert
|
||||
- if ($hashlist{"$hash.$suffix"} eq $fprint) {
|
||||
- print STDERR "WARNING: Skipping duplicate certificate $fname\n";
|
||||
- return;
|
||||
- }
|
||||
- $suffix++;
|
||||
- }
|
||||
- $hash .= ".$suffix";
|
||||
- if ($symlink_exists) {
|
||||
- print "link $fname -> $hash\n" if $verbose;
|
||||
- symlink $fname, $hash || warn "Can't symlink, $!";
|
||||
- } else {
|
||||
- print "copy $fname -> $hash\n" if $verbose;
|
||||
- if (open($in, "<", $fname)) {
|
||||
- if (open($out,">", $hash)) {
|
||||
- print $out $_ while (<$in>);
|
||||
- close $out;
|
||||
- } else {
|
||||
- warn "can't open $hash for write, $!";
|
||||
- }
|
||||
- close $in;
|
||||
- } else {
|
||||
- warn "can't open $fname for read, $!";
|
||||
- }
|
||||
- }
|
||||
- $hashlist{$hash} = $fprint;
|
||||
+ link_hash($_[0], 'cert');
|
||||
}
|
||||
|
||||
# Same as above except for a CRL. CRL links are of the form <hash>.r<n>
|
||||
|
||||
sub link_hash_crl {
|
||||
- my $fname = $_[0];
|
||||
- my ($hash, $fprint) = compute_hash($openssl, "crl", $crlhash,
|
||||
- "-fingerprint", "-noout",
|
||||
- "-in", $fname);
|
||||
- chomp $hash;
|
||||
- chomp $fprint;
|
||||
- return if !$hash;
|
||||
- $fprint =~ s/^.*=//;
|
||||
- $fprint =~ tr/://d;
|
||||
- my $suffix = 0;
|
||||
- # Search for an unused hash filename
|
||||
- while(exists $hashlist{"$hash.r$suffix"}) {
|
||||
- # Hash matches: if fingerprint matches its a duplicate cert
|
||||
- if ($hashlist{"$hash.r$suffix"} eq $fprint) {
|
||||
- print STDERR "WARNING: Skipping duplicate CRL $fname\n";
|
||||
- return;
|
||||
- }
|
||||
- $suffix++;
|
||||
- }
|
||||
- $hash .= ".r$suffix";
|
||||
- if ($symlink_exists) {
|
||||
- print "link $fname -> $hash\n" if $verbose;
|
||||
- symlink $fname, $hash || warn "Can't symlink, $!";
|
||||
- } else {
|
||||
- print "cp $fname -> $hash\n" if $verbose;
|
||||
- system ("cp", $fname, $hash);
|
||||
- warn "Can't copy, $!" if ($? >> 8) != 0;
|
||||
- }
|
||||
- $hashlist{$hash} = $fprint;
|
||||
+ link_hash($_[0], 'crl');
|
||||
+}
|
||||
+
|
||||
+sub link_hash {
|
||||
+ my ($fname, $type) = @_;
|
||||
+ my $is_cert = $type eq 'cert';
|
||||
+
|
||||
+ my ($hash, $fprint) = compute_hash($openssl,
|
||||
+ $is_cert ? "x509" : "crl",
|
||||
+ $is_cert ? $x509hash : $crlhash,
|
||||
+ "-fingerprint", "-noout",
|
||||
+ "-in", $fname);
|
||||
+ chomp $hash;
|
||||
+ chomp $fprint;
|
||||
+ return if !$hash;
|
||||
+ $fprint =~ s/^.*=//;
|
||||
+ $fprint =~ tr/://d;
|
||||
+ my $suffix = 0;
|
||||
+ # Search for an unused hash filename
|
||||
+ my $crlmark = $is_cert ? "" : "r";
|
||||
+ while(exists $hashlist{"$hash.$crlmark$suffix"}) {
|
||||
+ # Hash matches: if fingerprint matches its a duplicate cert
|
||||
+ if ($hashlist{"$hash.$crlmark$suffix"} eq $fprint) {
|
||||
+ my $what = $is_cert ? 'certificate' : 'CRL';
|
||||
+ print STDERR "WARNING: Skipping duplicate $what $fname\n";
|
||||
+ return;
|
||||
+ }
|
||||
+ $suffix++;
|
||||
+ }
|
||||
+ $hash .= ".$crlmark$suffix";
|
||||
+ if ($symlink_exists) {
|
||||
+ print "link $fname -> $hash\n" if $verbose;
|
||||
+ symlink $fname, $hash || warn "Can't symlink, $!";
|
||||
+ } else {
|
||||
+ print "copy $fname -> $hash\n" if $verbose;
|
||||
+ copy_file($fname, $hash);
|
||||
+ }
|
||||
+ $hashlist{$hash} = $fprint;
|
||||
}
|
||||
--
|
||||
1.8.3.1
|
||||
|
@ -0,0 +1,73 @@
|
||||
From 919925673d6c9cfed3c1085497f5dfbbed5fc431 Mon Sep 17 00:00:00 2001
|
||||
From: Alex Chernyakhovsky <achernya@google.com>
|
||||
Date: Thu, 16 Jun 2022 12:00:22 +1000
|
||||
Subject: [PATCH] Fix AES OCB encrypt/decrypt for x86 AES-NI
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
aesni_ocb_encrypt and aesni_ocb_decrypt operate by having a fast-path
|
||||
that performs operations on 6 16-byte blocks concurrently (the
|
||||
"grandloop") and then proceeds to handle the "short" tail (which can
|
||||
be anywhere from 0 to 5 blocks) that remain.
|
||||
|
||||
As part of initialization, the assembly initializes $len to the true
|
||||
length, less 96 bytes and converts it to a pointer so that the $inp
|
||||
can be compared to it. Each iteration of "grandloop" checks to see if
|
||||
there's a full 96-byte chunk to process, and if so, continues. Once
|
||||
this has been exhausted, it falls through to "short", which handles
|
||||
the remaining zero to five blocks.
|
||||
|
||||
Unfortunately, the jump at the end of "grandloop" had a fencepost
|
||||
error, doing a `jb` ("jump below") rather than `jbe` (jump below or
|
||||
equal). This should be `jbe`, as $inp is pointing to the *end* of the
|
||||
chunk currently being handled. If $inp == $len, that means that
|
||||
there's a whole 96-byte chunk waiting to be handled. If $inp > $len,
|
||||
then there's 5 or fewer 16-byte blocks left to be handled, and the
|
||||
fall-through is intended.
|
||||
|
||||
The net effect of `jb` instead of `jbe` is that the last 16-byte block
|
||||
of the last 96-byte chunk was completely omitted. The contents of
|
||||
`out` in this position were never written to. Additionally, since
|
||||
those bytes were never processed, the authentication tag generated is
|
||||
also incorrect.
|
||||
|
||||
The same fencepost error, and identical logic, exists in both
|
||||
aesni_ocb_encrypt and aesni_ocb_decrypt.
|
||||
|
||||
This addresses CVE-2022-2097.
|
||||
|
||||
Co-authored-by: Alejandro Sedeño <asedeno@google.com>
|
||||
Co-authored-by: David Benjamin <davidben@google.com>
|
||||
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
---
|
||||
crypto/aes/asm/aesni-x86.pl | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/crypto/aes/asm/aesni-x86.pl b/crypto/aes/asm/aesni-x86.pl
|
||||
index fe2b265..812758e 100644
|
||||
--- a/crypto/aes/asm/aesni-x86.pl
|
||||
+++ b/crypto/aes/asm/aesni-x86.pl
|
||||
@@ -2027,7 +2027,7 @@ my ($l_,$block,$i1,$i3,$i5) = ($rounds_,$key_,$rounds,$len,$out);
|
||||
&movdqu (&QWP(-16*2,$out,$inp),$inout4);
|
||||
&movdqu (&QWP(-16*1,$out,$inp),$inout5);
|
||||
&cmp ($inp,$len); # done yet?
|
||||
- &jb (&label("grandloop"));
|
||||
+ &jbe (&label("grandloop"));
|
||||
|
||||
&set_label("short");
|
||||
&add ($len,16*6);
|
||||
@@ -2453,7 +2453,7 @@ my ($l_,$block,$i1,$i3,$i5) = ($rounds_,$key_,$rounds,$len,$out);
|
||||
&pxor ($rndkey1,$inout5);
|
||||
&movdqu (&QWP(-16*1,$out,$inp),$inout5);
|
||||
&cmp ($inp,$len); # done yet?
|
||||
- &jb (&label("grandloop"));
|
||||
+ &jbe (&label("grandloop"));
|
||||
|
||||
&set_label("short");
|
||||
&add ($len,16*6);
|
||||
--
|
||||
1.8.3.1
|
||||
|
@ -1,65 +0,0 @@
|
||||
commit 919925673d6c9cfed3c1085497f5dfbbed5fc431
|
||||
Author: Alex Chernyakhovsky <achernya@google.com>
|
||||
Date: Thu Jun 16 12:00:22 2022 +1000
|
||||
|
||||
Fix AES OCB encrypt/decrypt for x86 AES-NI
|
||||
|
||||
aesni_ocb_encrypt and aesni_ocb_decrypt operate by having a fast-path
|
||||
that performs operations on 6 16-byte blocks concurrently (the
|
||||
"grandloop") and then proceeds to handle the "short" tail (which can
|
||||
be anywhere from 0 to 5 blocks) that remain.
|
||||
|
||||
As part of initialization, the assembly initializes $len to the true
|
||||
length, less 96 bytes and converts it to a pointer so that the $inp
|
||||
can be compared to it. Each iteration of "grandloop" checks to see if
|
||||
there's a full 96-byte chunk to process, and if so, continues. Once
|
||||
this has been exhausted, it falls through to "short", which handles
|
||||
the remaining zero to five blocks.
|
||||
|
||||
Unfortunately, the jump at the end of "grandloop" had a fencepost
|
||||
error, doing a `jb` ("jump below") rather than `jbe` (jump below or
|
||||
equal). This should be `jbe`, as $inp is pointing to the *end* of the
|
||||
chunk currently being handled. If $inp == $len, that means that
|
||||
there's a whole 96-byte chunk waiting to be handled. If $inp > $len,
|
||||
then there's 5 or fewer 16-byte blocks left to be handled, and the
|
||||
fall-through is intended.
|
||||
|
||||
The net effect of `jb` instead of `jbe` is that the last 16-byte block
|
||||
of the last 96-byte chunk was completely omitted. The contents of
|
||||
`out` in this position were never written to. Additionally, since
|
||||
those bytes were never processed, the authentication tag generated is
|
||||
also incorrect.
|
||||
|
||||
The same fencepost error, and identical logic, exists in both
|
||||
aesni_ocb_encrypt and aesni_ocb_decrypt.
|
||||
|
||||
This addresses CVE-2022-2097.
|
||||
|
||||
Co-authored-by: Alejandro Sedeño <asedeno@google.com>
|
||||
Co-authored-by: David Benjamin <davidben@google.com>
|
||||
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
|
||||
diff --git a/crypto/aes/asm/aesni-x86.pl b/crypto/aes/asm/aesni-x86.pl
|
||||
index fe2b26542a..812758e02e 100644
|
||||
--- a/crypto/aes/asm/aesni-x86.pl
|
||||
+++ b/crypto/aes/asm/aesni-x86.pl
|
||||
@@ -2027,7 +2027,7 @@ my ($l_,$block,$i1,$i3,$i5) = ($rounds_,$key_,$rounds,$len,$out);
|
||||
&movdqu (&QWP(-16*2,$out,$inp),$inout4);
|
||||
&movdqu (&QWP(-16*1,$out,$inp),$inout5);
|
||||
&cmp ($inp,$len); # done yet?
|
||||
- &jb (&label("grandloop"));
|
||||
+ &jbe (&label("grandloop"));
|
||||
|
||||
&set_label("short");
|
||||
&add ($len,16*6);
|
||||
@@ -2453,7 +2453,7 @@ my ($l_,$block,$i1,$i3,$i5) = ($rounds_,$key_,$rounds,$len,$out);
|
||||
&pxor ($rndkey1,$inout5);
|
||||
&movdqu (&QWP(-16*1,$out,$inp),$inout5);
|
||||
&cmp ($inp,$len); # done yet?
|
||||
- &jb (&label("grandloop"));
|
||||
+ &jbe (&label("grandloop"));
|
||||
|
||||
&set_label("short");
|
||||
&add ($len,16*6);
|
@ -1,804 +0,0 @@
|
||||
From 43d8f88511991533f53680a751e9326999a6a31f Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Fri, 20 Jan 2023 15:26:54 +0000
|
||||
Subject: [PATCH] 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>
|
||||
---
|
||||
crypto/bn/bn_blind.c | 14 -
|
||||
crypto/bn/bn_err.c | 2 +
|
||||
crypto/bn/bn_local.h | 14 +
|
||||
crypto/bn/build.info | 3 +-
|
||||
crypto/bn/rsa_sup_mul.c | 614 ++++++++++++++++++++++++++++++++++++++++
|
||||
crypto/err/openssl.txt | 3 +-
|
||||
crypto/rsa/rsa_ossl.c | 17 +-
|
||||
include/crypto/bn.h | 5 +
|
||||
include/openssl/bnerr.h | 1 +
|
||||
9 files changed, 653 insertions(+), 20 deletions(-)
|
||||
create mode 100644 crypto/bn/rsa_sup_mul.c
|
||||
|
||||
diff --git a/crypto/bn/bn_blind.c b/crypto/bn/bn_blind.c
|
||||
index 76fc7ebcff..6e9d239321 100644
|
||||
--- a/crypto/bn/bn_blind.c
|
||||
+++ b/crypto/bn/bn_blind.c
|
||||
@@ -13,20 +13,6 @@
|
||||
|
||||
#define BN_BLINDING_COUNTER 32
|
||||
|
||||
-struct bn_blinding_st {
|
||||
- BIGNUM *A;
|
||||
- BIGNUM *Ai;
|
||||
- BIGNUM *e;
|
||||
- BIGNUM *mod; /* just a reference */
|
||||
- CRYPTO_THREAD_ID tid;
|
||||
- int counter;
|
||||
- unsigned long flags;
|
||||
- BN_MONT_CTX *m_ctx;
|
||||
- int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
- const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
|
||||
- CRYPTO_RWLOCK *lock;
|
||||
-};
|
||||
-
|
||||
BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)
|
||||
{
|
||||
BN_BLINDING *ret = NULL;
|
||||
diff --git a/crypto/bn/bn_err.c b/crypto/bn/bn_err.c
|
||||
index dd87c152cf..3dd8d9a568 100644
|
||||
--- a/crypto/bn/bn_err.c
|
||||
+++ b/crypto/bn/bn_err.c
|
||||
@@ -73,6 +73,8 @@ static const ERR_STRING_DATA BN_str_functs[] = {
|
||||
{ERR_PACK(ERR_LIB_BN, BN_F_BN_SET_WORDS, 0), "bn_set_words"},
|
||||
{ERR_PACK(ERR_LIB_BN, BN_F_BN_STACK_PUSH, 0), "BN_STACK_push"},
|
||||
{ERR_PACK(ERR_LIB_BN, BN_F_BN_USUB, 0), "BN_usub"},
|
||||
+ {ERR_PACK(ERR_LIB_BN, BN_F_OSSL_BN_RSA_DO_UNBLIND, 0),
|
||||
+ "ossl_bn_rsa_do_unblind"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
diff --git a/crypto/bn/bn_local.h b/crypto/bn/bn_local.h
|
||||
index 62a969b134..4d8cb64675 100644
|
||||
--- a/crypto/bn/bn_local.h
|
||||
+++ b/crypto/bn/bn_local.h
|
||||
@@ -283,6 +283,20 @@ struct bn_gencb_st {
|
||||
} cb;
|
||||
};
|
||||
|
||||
+struct bn_blinding_st {
|
||||
+ BIGNUM *A;
|
||||
+ BIGNUM *Ai;
|
||||
+ BIGNUM *e;
|
||||
+ BIGNUM *mod; /* just a reference */
|
||||
+ CRYPTO_THREAD_ID tid;
|
||||
+ int counter;
|
||||
+ unsigned long flags;
|
||||
+ BN_MONT_CTX *m_ctx;
|
||||
+ int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
|
||||
+ const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
|
||||
+ CRYPTO_RWLOCK *lock;
|
||||
+};
|
||||
+
|
||||
/*-
|
||||
* BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions
|
||||
*
|
||||
diff --git a/crypto/bn/build.info b/crypto/bn/build.info
|
||||
index b9ed5322fa..c9fe2fdada 100644
|
||||
--- a/crypto/bn/build.info
|
||||
+++ b/crypto/bn/build.info
|
||||
@@ -5,7 +5,8 @@ SOURCE[../../libcrypto]=\
|
||||
bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c \
|
||||
{- $target{bn_asm_src} -} \
|
||||
bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c bn_gf2m.c bn_nist.c \
|
||||
- bn_depr.c bn_const.c bn_x931p.c bn_intern.c bn_dh.c bn_srp.c
|
||||
+ bn_depr.c bn_const.c bn_x931p.c bn_intern.c bn_dh.c bn_srp.c \
|
||||
+ rsa_sup_mul.c
|
||||
|
||||
INCLUDE[bn_exp.o]=..
|
||||
|
||||
diff --git a/crypto/bn/rsa_sup_mul.c b/crypto/bn/rsa_sup_mul.c
|
||||
new file mode 100644
|
||||
index 0000000000..acafefd5fe
|
||||
--- /dev/null
|
||||
+++ b/crypto/bn/rsa_sup_mul.c
|
||||
@@ -0,0 +1,614 @@
|
||||
+#include <openssl/e_os2.h>
|
||||
+#include <stddef.h>
|
||||
+#include <sys/types.h>
|
||||
+#include <string.h>
|
||||
+#include <openssl/bn.h>
|
||||
+#include <openssl/err.h>
|
||||
+#include <openssl/rsaerr.h>
|
||||
+#include "internal/numbers.h"
|
||||
+#include "internal/constant_time.h"
|
||||
+#include "bn_local.h"
|
||||
+
|
||||
+# if BN_BYTES == 8
|
||||
+typedef uint64_t limb_t;
|
||||
+# if defined(__SIZEOF_INT128__) && __SIZEOF_INT128__ == 16
|
||||
+/* nonstandard; implemented by gcc on 64-bit platforms */
|
||||
+typedef __uint128_t limb2_t;
|
||||
+# define HAVE_LIMB2_T
|
||||
+# endif
|
||||
+# define LIMB_BIT_SIZE 64
|
||||
+# define LIMB_BYTE_SIZE 8
|
||||
+# elif BN_BYTES == 4
|
||||
+typedef uint32_t limb_t;
|
||||
+typedef uint64_t limb2_t;
|
||||
+# define LIMB_BIT_SIZE 32
|
||||
+# define LIMB_BYTE_SIZE 4
|
||||
+# define HAVE_LIMB2_T
|
||||
+# else
|
||||
+# error "Not supported"
|
||||
+# endif
|
||||
+
|
||||
+/*
|
||||
+ * For multiplication we're using schoolbook multiplication,
|
||||
+ * so if we have two numbers, each with 6 "digits" (words)
|
||||
+ * the multiplication is calculated as follows:
|
||||
+ * A B C D E F
|
||||
+ * x I J K L M N
|
||||
+ * --------------
|
||||
+ * N*F
|
||||
+ * N*E
|
||||
+ * N*D
|
||||
+ * N*C
|
||||
+ * N*B
|
||||
+ * N*A
|
||||
+ * M*F
|
||||
+ * M*E
|
||||
+ * M*D
|
||||
+ * M*C
|
||||
+ * M*B
|
||||
+ * M*A
|
||||
+ * L*F
|
||||
+ * L*E
|
||||
+ * L*D
|
||||
+ * L*C
|
||||
+ * L*B
|
||||
+ * L*A
|
||||
+ * K*F
|
||||
+ * K*E
|
||||
+ * K*D
|
||||
+ * K*C
|
||||
+ * K*B
|
||||
+ * K*A
|
||||
+ * J*F
|
||||
+ * J*E
|
||||
+ * J*D
|
||||
+ * J*C
|
||||
+ * J*B
|
||||
+ * J*A
|
||||
+ * I*F
|
||||
+ * I*E
|
||||
+ * I*D
|
||||
+ * I*C
|
||||
+ * I*B
|
||||
+ * + I*A
|
||||
+ * ==========================
|
||||
+ * N*B N*D N*F
|
||||
+ * + N*A N*C N*E
|
||||
+ * + M*B M*D M*F
|
||||
+ * + M*A M*C M*E
|
||||
+ * + L*B L*D L*F
|
||||
+ * + L*A L*C L*E
|
||||
+ * + K*B K*D K*F
|
||||
+ * + K*A K*C K*E
|
||||
+ * + J*B J*D J*F
|
||||
+ * + J*A J*C J*E
|
||||
+ * + I*B I*D I*F
|
||||
+ * + I*A I*C I*E
|
||||
+ *
|
||||
+ * 1+1 1+3 1+5
|
||||
+ * 1+0 1+2 1+4
|
||||
+ * 0+1 0+3 0+5
|
||||
+ * 0+0 0+2 0+4
|
||||
+ *
|
||||
+ * 0 1 2 3 4 5 6
|
||||
+ * which requires n^2 multiplications and 2n full length additions
|
||||
+ * as we can keep every other result of limb multiplication in two separate
|
||||
+ * limbs
|
||||
+ */
|
||||
+
|
||||
+#if defined HAVE_LIMB2_T
|
||||
+static ossl_inline void _mul_limb(limb_t *hi, limb_t *lo, limb_t a, limb_t b)
|
||||
+{
|
||||
+ limb2_t t;
|
||||
+ /*
|
||||
+ * this is idiomatic code to tell compiler to use the native mul
|
||||
+ * those three lines will actually compile to single instruction
|
||||
+ */
|
||||
+
|
||||
+ t = (limb2_t)a * b;
|
||||
+ *hi = t >> LIMB_BIT_SIZE;
|
||||
+ *lo = (limb_t)t;
|
||||
+}
|
||||
+#elif (BN_BYTES == 8) && (defined _MSC_VER)
|
||||
+/* https://learn.microsoft.com/en-us/cpp/intrinsics/umul128?view=msvc-170 */
|
||||
+#pragma intrinsic(_umul128)
|
||||
+static ossl_inline void _mul_limb(limb_t *hi, limb_t *lo, limb_t a, limb_t b)
|
||||
+{
|
||||
+ *lo = _umul128(a, b, hi);
|
||||
+}
|
||||
+#else
|
||||
+/*
|
||||
+ * if the compiler doesn't have either a 128bit data type nor a "return
|
||||
+ * high 64 bits of multiplication"
|
||||
+ */
|
||||
+static ossl_inline void _mul_limb(limb_t *hi, limb_t *lo, limb_t a, limb_t b)
|
||||
+{
|
||||
+ limb_t a_low = (limb_t)(uint32_t)a;
|
||||
+ limb_t a_hi = a >> 32;
|
||||
+ limb_t b_low = (limb_t)(uint32_t)b;
|
||||
+ limb_t b_hi = b >> 32;
|
||||
+
|
||||
+ limb_t p0 = a_low * b_low;
|
||||
+ limb_t p1 = a_low * b_hi;
|
||||
+ limb_t p2 = a_hi * b_low;
|
||||
+ limb_t p3 = a_hi * b_hi;
|
||||
+
|
||||
+ uint32_t cy = (uint32_t)(((p0 >> 32) + (uint32_t)p1 + (uint32_t)p2) >> 32);
|
||||
+
|
||||
+ *lo = p0 + (p1 << 32) + (p2 << 32);
|
||||
+ *hi = p3 + (p1 >> 32) + (p2 >> 32) + cy;
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+/* add two limbs with carry in, return carry out */
|
||||
+static ossl_inline limb_t _add_limb(limb_t *ret, limb_t a, limb_t b, limb_t carry)
|
||||
+{
|
||||
+ limb_t carry1, carry2, t;
|
||||
+ /*
|
||||
+ * `c = a + b; if (c < a)` is idiomatic code that makes compilers
|
||||
+ * use add with carry on assembly level
|
||||
+ */
|
||||
+
|
||||
+ *ret = a + carry;
|
||||
+ if (*ret < a)
|
||||
+ carry1 = 1;
|
||||
+ else
|
||||
+ carry1 = 0;
|
||||
+
|
||||
+ t = *ret;
|
||||
+ *ret = t + b;
|
||||
+ if (*ret < t)
|
||||
+ carry2 = 1;
|
||||
+ else
|
||||
+ carry2 = 0;
|
||||
+
|
||||
+ return carry1 + carry2;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * add two numbers of the same size, return overflow
|
||||
+ *
|
||||
+ * add a to b, place result in ret; all arrays need to be n limbs long
|
||||
+ * return overflow from addition (0 or 1)
|
||||
+ */
|
||||
+static ossl_inline limb_t add(limb_t *ret, limb_t *a, limb_t *b, size_t n)
|
||||
+{
|
||||
+ limb_t c = 0;
|
||||
+ ossl_ssize_t i;
|
||||
+
|
||||
+ for(i = n - 1; i > -1; i--)
|
||||
+ c = _add_limb(&ret[i], a[i], b[i], c);
|
||||
+
|
||||
+ return c;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * return number of limbs necessary for temporary values
|
||||
+ * when multiplying numbers n limbs large
|
||||
+ */
|
||||
+static ossl_inline size_t mul_limb_numb(size_t n)
|
||||
+{
|
||||
+ return 2 * n * 2;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * multiply two numbers of the same size
|
||||
+ *
|
||||
+ * multiply a by b, place result in ret; a and b need to be n limbs long
|
||||
+ * ret needs to be 2*n limbs long, tmp needs to be mul_limb_numb(n) limbs
|
||||
+ * long
|
||||
+ */
|
||||
+static void limb_mul(limb_t *ret, limb_t *a, limb_t *b, size_t n, limb_t *tmp)
|
||||
+{
|
||||
+ limb_t *r_odd, *r_even;
|
||||
+ size_t i, j, k;
|
||||
+
|
||||
+ r_odd = tmp;
|
||||
+ r_even = &tmp[2 * n];
|
||||
+
|
||||
+ memset(ret, 0, 2 * n * sizeof(limb_t));
|
||||
+
|
||||
+ for (i = 0; i < n; i++) {
|
||||
+ for (k = 0; k < i + n + 1; k++) {
|
||||
+ r_even[k] = 0;
|
||||
+ r_odd[k] = 0;
|
||||
+ }
|
||||
+ for (j = 0; j < n; j++) {
|
||||
+ /*
|
||||
+ * place results from even and odd limbs in separate arrays so that
|
||||
+ * we don't have to calculate overflow every time we get individual
|
||||
+ * limb multiplication result
|
||||
+ */
|
||||
+ if (j % 2 == 0)
|
||||
+ _mul_limb(&r_even[i + j], &r_even[i + j + 1], a[i], b[j]);
|
||||
+ else
|
||||
+ _mul_limb(&r_odd[i + j], &r_odd[i + j + 1], a[i], b[j]);
|
||||
+ }
|
||||
+ /*
|
||||
+ * skip the least significant limbs when adding multiples of
|
||||
+ * more significant limbs (they're zero anyway)
|
||||
+ */
|
||||
+ add(ret, ret, r_even, n + i + 1);
|
||||
+ add(ret, ret, r_odd, n + i + 1);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/* modifies the value in place by performing a right shift by one bit */
|
||||
+static ossl_inline void rshift1(limb_t *val, size_t n)
|
||||
+{
|
||||
+ limb_t shift_in = 0, shift_out = 0;
|
||||
+ size_t i;
|
||||
+
|
||||
+ for (i = 0; i < n; i++) {
|
||||
+ shift_out = val[i] & 1;
|
||||
+ val[i] = shift_in << (LIMB_BIT_SIZE - 1) | (val[i] >> 1);
|
||||
+ shift_in = shift_out;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/* extend the LSB of flag to all bits of limb */
|
||||
+static ossl_inline limb_t mk_mask(limb_t flag)
|
||||
+{
|
||||
+ flag |= flag << 1;
|
||||
+ flag |= flag << 2;
|
||||
+ flag |= flag << 4;
|
||||
+ flag |= flag << 8;
|
||||
+ flag |= flag << 16;
|
||||
+#if (LIMB_BYTE_SIZE == 8)
|
||||
+ flag |= flag << 32;
|
||||
+#endif
|
||||
+ return flag;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * copy from either a or b to ret based on flag
|
||||
+ * when flag == 0, then copies from b
|
||||
+ * when flag == 1, then copies from a
|
||||
+ */
|
||||
+static ossl_inline void cselect(limb_t flag, limb_t *ret, limb_t *a, limb_t *b, size_t n)
|
||||
+{
|
||||
+ /*
|
||||
+ * would be more efficient with non volatile mask, but then gcc
|
||||
+ * generates code with jumps
|
||||
+ */
|
||||
+ volatile limb_t mask;
|
||||
+ size_t i;
|
||||
+
|
||||
+ mask = mk_mask(flag);
|
||||
+ for (i = 0; i < n; i++) {
|
||||
+#if (LIMB_BYTE_SIZE == 8)
|
||||
+ ret[i] = constant_time_select_64(mask, a[i], b[i]);
|
||||
+#else
|
||||
+ ret[i] = constant_time_select_32(mask, a[i], b[i]);
|
||||
+#endif
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static limb_t _sub_limb(limb_t *ret, limb_t a, limb_t b, limb_t borrow)
|
||||
+{
|
||||
+ limb_t borrow1, borrow2, t;
|
||||
+ /*
|
||||
+ * while it doesn't look constant-time, this is idiomatic code
|
||||
+ * to tell compilers to use the carry bit from subtraction
|
||||
+ */
|
||||
+
|
||||
+ *ret = a - borrow;
|
||||
+ if (*ret > a)
|
||||
+ borrow1 = 1;
|
||||
+ else
|
||||
+ borrow1 = 0;
|
||||
+
|
||||
+ t = *ret;
|
||||
+ *ret = t - b;
|
||||
+ if (*ret > t)
|
||||
+ borrow2 = 1;
|
||||
+ else
|
||||
+ borrow2 = 0;
|
||||
+
|
||||
+ return borrow1 + borrow2;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * place the result of a - b into ret, return the borrow bit.
|
||||
+ * All arrays need to be n limbs long
|
||||
+ */
|
||||
+static limb_t sub(limb_t *ret, limb_t *a, limb_t *b, size_t n)
|
||||
+{
|
||||
+ limb_t borrow = 0;
|
||||
+ ossl_ssize_t i;
|
||||
+
|
||||
+ for (i = n - 1; i > -1; i--)
|
||||
+ borrow = _sub_limb(&ret[i], a[i], b[i], borrow);
|
||||
+
|
||||
+ return borrow;
|
||||
+}
|
||||
+
|
||||
+/* return the number of limbs necessary to allocate for the mod() tmp operand */
|
||||
+static ossl_inline size_t mod_limb_numb(size_t anum, size_t modnum)
|
||||
+{
|
||||
+ return (anum + modnum) * 3;
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * calculate a % mod, place the result in ret
|
||||
+ * size of a is defined by anum, size of ret and mod is modnum,
|
||||
+ * size of tmp is returned by mod_limb_numb()
|
||||
+ */
|
||||
+static void mod(limb_t *ret, limb_t *a, size_t anum, limb_t *mod,
|
||||
+ size_t modnum, limb_t *tmp)
|
||||
+{
|
||||
+ limb_t *atmp, *modtmp, *rettmp;
|
||||
+ limb_t res;
|
||||
+ size_t i;
|
||||
+
|
||||
+ memset(tmp, 0, mod_limb_numb(anum, modnum) * LIMB_BYTE_SIZE);
|
||||
+
|
||||
+ atmp = tmp;
|
||||
+ modtmp = &tmp[anum + modnum];
|
||||
+ rettmp = &tmp[(anum + modnum) * 2];
|
||||
+
|
||||
+ for (i = modnum; i <modnum + anum; i++)
|
||||
+ atmp[i] = a[i-modnum];
|
||||
+
|
||||
+ for (i = 0; i < modnum; i++)
|
||||
+ modtmp[i] = mod[i];
|
||||
+
|
||||
+ for (i = 0; i < anum * LIMB_BIT_SIZE; i++) {
|
||||
+ rshift1(modtmp, anum + modnum);
|
||||
+ res = sub(rettmp, atmp, modtmp, anum+modnum);
|
||||
+ cselect(res, atmp, atmp, rettmp, anum+modnum);
|
||||
+ }
|
||||
+
|
||||
+ memcpy(ret, &atmp[anum], sizeof(limb_t) * modnum);
|
||||
+}
|
||||
+
|
||||
+/* necessary size of tmp for a _mul_add_limb() call with provided anum */
|
||||
+static ossl_inline size_t _mul_add_limb_numb(size_t anum)
|
||||
+{
|
||||
+ return 2 * (anum + 1);
|
||||
+}
|
||||
+
|
||||
+/* multiply a by m, add to ret, return carry */
|
||||
+static limb_t _mul_add_limb(limb_t *ret, limb_t *a, size_t anum,
|
||||
+ limb_t m, limb_t *tmp)
|
||||
+{
|
||||
+ limb_t carry = 0;
|
||||
+ limb_t *r_odd, *r_even;
|
||||
+ size_t i;
|
||||
+
|
||||
+ memset(tmp, 0, sizeof(limb_t) * (anum + 1) * 2);
|
||||
+
|
||||
+ r_odd = tmp;
|
||||
+ r_even = &tmp[anum + 1];
|
||||
+
|
||||
+ for (i = 0; i < anum; i++) {
|
||||
+ /*
|
||||
+ * place the results from even and odd limbs in separate arrays
|
||||
+ * so that we have to worry about carry just once
|
||||
+ */
|
||||
+ if (i % 2 == 0)
|
||||
+ _mul_limb(&r_even[i], &r_even[i + 1], a[i], m);
|
||||
+ else
|
||||
+ _mul_limb(&r_odd[i], &r_odd[i + 1], a[i], m);
|
||||
+ }
|
||||
+ /* assert: add() carry here will be equal zero */
|
||||
+ add(r_even, r_even, r_odd, anum + 1);
|
||||
+ /*
|
||||
+ * while here it will not overflow as the max value from multiplication
|
||||
+ * is -2 while max overflow from addition is 1, so the max value of
|
||||
+ * carry is -1 (i.e. max int)
|
||||
+ */
|
||||
+ carry = add(ret, ret, &r_even[1], anum) + r_even[0];
|
||||
+
|
||||
+ return carry;
|
||||
+}
|
||||
+
|
||||
+static ossl_inline size_t mod_montgomery_limb_numb(size_t modnum)
|
||||
+{
|
||||
+ return modnum * 2 + _mul_add_limb_numb(modnum);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * calculate a % mod, place result in ret
|
||||
+ * assumes that a is in Montgomery form with the R (Montgomery modulus) being
|
||||
+ * smallest power of two big enough to fit mod and that's also a power
|
||||
+ * of the count of number of bits in limb_t (B).
|
||||
+ * For calculation, we also need n', such that mod * n' == -1 mod B.
|
||||
+ * anum must be <= 2 * modnum
|
||||
+ * ret needs to be modnum words long
|
||||
+ * tmp needs to be mod_montgomery_limb_numb(modnum) limbs long
|
||||
+ */
|
||||
+static void mod_montgomery(limb_t *ret, limb_t *a, size_t anum, limb_t *mod,
|
||||
+ size_t modnum, limb_t ni0, limb_t *tmp)
|
||||
+{
|
||||
+ limb_t carry, v;
|
||||
+ limb_t *res, *rp, *tmp2;
|
||||
+ ossl_ssize_t i;
|
||||
+
|
||||
+ res = tmp;
|
||||
+ /*
|
||||
+ * for intermediate result we need an integer twice as long as modulus
|
||||
+ * but keep the input in the least significant limbs
|
||||
+ */
|
||||
+ memset(res, 0, sizeof(limb_t) * (modnum * 2));
|
||||
+ memcpy(&res[modnum * 2 - anum], a, sizeof(limb_t) * anum);
|
||||
+ rp = &res[modnum];
|
||||
+ tmp2 = &res[modnum * 2];
|
||||
+
|
||||
+ carry = 0;
|
||||
+
|
||||
+ /* add multiples of the modulus to the value until R divides it cleanly */
|
||||
+ for (i = modnum; i > 0; i--, rp--) {
|
||||
+ v = _mul_add_limb(rp, mod, modnum, rp[modnum - 1] * ni0, tmp2);
|
||||
+ v = v + carry + rp[-1];
|
||||
+ carry |= (v != rp[-1]);
|
||||
+ carry &= (v <= rp[-1]);
|
||||
+ rp[-1] = v;
|
||||
+ }
|
||||
+
|
||||
+ /* perform the final reduction by mod... */
|
||||
+ carry -= sub(ret, rp, mod, modnum);
|
||||
+
|
||||
+ /* ...conditionally */
|
||||
+ cselect(carry, ret, rp, ret, modnum);
|
||||
+}
|
||||
+
|
||||
+/* allocated buffer should be freed afterwards */
|
||||
+static void BN_to_limb(const BIGNUM *bn, limb_t *buf, size_t limbs)
|
||||
+{
|
||||
+ int i;
|
||||
+ int real_limbs = (BN_num_bytes(bn) + LIMB_BYTE_SIZE - 1) / LIMB_BYTE_SIZE;
|
||||
+ limb_t *ptr = buf + (limbs - real_limbs);
|
||||
+
|
||||
+ for (i = 0; i < real_limbs; i++)
|
||||
+ ptr[i] = bn->d[real_limbs - i - 1];
|
||||
+}
|
||||
+
|
||||
+#if LIMB_BYTE_SIZE == 8
|
||||
+static ossl_inline uint64_t be64(uint64_t host)
|
||||
+{
|
||||
+ const union {
|
||||
+ long one;
|
||||
+ char little;
|
||||
+ } is_endian = { 1 };
|
||||
+
|
||||
+ if (is_endian.little) {
|
||||
+ uint64_t big = 0;
|
||||
+
|
||||
+ big |= (host & 0xff00000000000000) >> 56;
|
||||
+ big |= (host & 0x00ff000000000000) >> 40;
|
||||
+ big |= (host & 0x0000ff0000000000) >> 24;
|
||||
+ big |= (host & 0x000000ff00000000) >> 8;
|
||||
+ big |= (host & 0x00000000ff000000) << 8;
|
||||
+ big |= (host & 0x0000000000ff0000) << 24;
|
||||
+ big |= (host & 0x000000000000ff00) << 40;
|
||||
+ big |= (host & 0x00000000000000ff) << 56;
|
||||
+ return big;
|
||||
+ } else {
|
||||
+ return host;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+#else
|
||||
+/* Not all platforms have htobe32(). */
|
||||
+static ossl_inline uint32_t be32(uint32_t host)
|
||||
+{
|
||||
+ const union {
|
||||
+ long one;
|
||||
+ char little;
|
||||
+ } is_endian = { 1 };
|
||||
+
|
||||
+ if (is_endian.little) {
|
||||
+ uint32_t big = 0;
|
||||
+
|
||||
+ big |= (host & 0xff000000) >> 24;
|
||||
+ big |= (host & 0x00ff0000) >> 8;
|
||||
+ big |= (host & 0x0000ff00) << 8;
|
||||
+ big |= (host & 0x000000ff) << 24;
|
||||
+ return big;
|
||||
+ } else {
|
||||
+ return host;
|
||||
+ }
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+/*
|
||||
+ * We assume that intermediate, possible_arg2, blinding, and ctx are used
|
||||
+ * similar to BN_BLINDING_invert_ex() arguments.
|
||||
+ * to_mod is RSA modulus.
|
||||
+ * buf and num is the serialization buffer and its length.
|
||||
+ *
|
||||
+ * Here we use classic/Montgomery multiplication and modulo. After the calculation finished
|
||||
+ * we serialize the new structure instead of BIGNUMs taking endianness into account.
|
||||
+ */
|
||||
+int ossl_bn_rsa_do_unblind(const BIGNUM *intermediate,
|
||||
+ const BN_BLINDING *blinding,
|
||||
+ const BIGNUM *possible_arg2,
|
||||
+ const BIGNUM *to_mod, BN_CTX *ctx,
|
||||
+ unsigned char *buf, int num)
|
||||
+{
|
||||
+ limb_t *l_im = NULL, *l_mul = NULL, *l_mod = NULL;
|
||||
+ limb_t *l_ret = NULL, *l_tmp = NULL, l_buf;
|
||||
+ size_t l_im_count = 0, l_mul_count = 0, l_size = 0, l_mod_count = 0;
|
||||
+ size_t l_tmp_count = 0;
|
||||
+ int ret = 0;
|
||||
+ size_t i;
|
||||
+ unsigned char *tmp;
|
||||
+ const BIGNUM *arg1 = intermediate;
|
||||
+ const BIGNUM *arg2 = (possible_arg2 == NULL) ? blinding->Ai : possible_arg2;
|
||||
+
|
||||
+ l_im_count = (BN_num_bytes(arg1) + LIMB_BYTE_SIZE - 1) / LIMB_BYTE_SIZE;
|
||||
+ l_mul_count = (BN_num_bytes(arg2) + LIMB_BYTE_SIZE - 1) / LIMB_BYTE_SIZE;
|
||||
+ l_mod_count = (BN_num_bytes(to_mod) + LIMB_BYTE_SIZE - 1) / LIMB_BYTE_SIZE;
|
||||
+
|
||||
+ l_size = l_im_count > l_mul_count ? l_im_count : l_mul_count;
|
||||
+ l_im = OPENSSL_zalloc(l_size * LIMB_BYTE_SIZE);
|
||||
+ l_mul = OPENSSL_zalloc(l_size * LIMB_BYTE_SIZE);
|
||||
+ l_mod = OPENSSL_zalloc(l_mod_count * LIMB_BYTE_SIZE);
|
||||
+
|
||||
+ if ((l_im == NULL) || (l_mul == NULL) || (l_mod == NULL))
|
||||
+ goto err;
|
||||
+
|
||||
+ BN_to_limb(arg1, l_im, l_size);
|
||||
+ BN_to_limb(arg2, l_mul, l_size);
|
||||
+ BN_to_limb(to_mod, l_mod, l_mod_count);
|
||||
+
|
||||
+ l_ret = OPENSSL_malloc(2 * l_size * LIMB_BYTE_SIZE);
|
||||
+
|
||||
+ if (blinding->m_ctx != NULL) {
|
||||
+ l_tmp_count = mul_limb_numb(l_size) > mod_montgomery_limb_numb(l_mod_count) ?
|
||||
+ mul_limb_numb(l_size) : mod_montgomery_limb_numb(l_mod_count);
|
||||
+ l_tmp = OPENSSL_malloc(l_tmp_count * LIMB_BYTE_SIZE);
|
||||
+ } else {
|
||||
+ l_tmp_count = mul_limb_numb(l_size) > mod_limb_numb(2 * l_size, l_mod_count) ?
|
||||
+ mul_limb_numb(l_size) : mod_limb_numb(2 * l_size, l_mod_count);
|
||||
+ l_tmp = OPENSSL_malloc(l_tmp_count * LIMB_BYTE_SIZE);
|
||||
+ }
|
||||
+
|
||||
+ if ((l_ret == NULL) || (l_tmp == NULL))
|
||||
+ goto err;
|
||||
+
|
||||
+ if (blinding->m_ctx != NULL) {
|
||||
+ limb_mul(l_ret, l_im, l_mul, l_size, l_tmp);
|
||||
+ mod_montgomery(l_ret, l_ret, 2 * l_size, l_mod, l_mod_count,
|
||||
+ blinding->m_ctx->n0[0], l_tmp);
|
||||
+ } else {
|
||||
+ limb_mul(l_ret, l_im, l_mul, l_size, l_tmp);
|
||||
+ mod(l_ret, l_ret, 2 * l_size, l_mod, l_mod_count, l_tmp);
|
||||
+ }
|
||||
+
|
||||
+ /* modulus size in bytes can be equal to num but after limbs conversion it becomes bigger */
|
||||
+ if (num < BN_num_bytes(to_mod)) {
|
||||
+ BNerr(BN_F_OSSL_BN_RSA_DO_UNBLIND, ERR_R_PASSED_INVALID_ARGUMENT);
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ memset(buf, 0, num);
|
||||
+ tmp = buf + num - BN_num_bytes(to_mod);
|
||||
+ for (i = 0; i < l_mod_count; i++) {
|
||||
+#if LIMB_BYTE_SIZE == 8
|
||||
+ l_buf = be64(l_ret[i]);
|
||||
+#else
|
||||
+ l_buf = be32(l_ret[i]);
|
||||
+#endif
|
||||
+ if (i == 0) {
|
||||
+ int delta = LIMB_BYTE_SIZE - ((l_mod_count * LIMB_BYTE_SIZE) - num);
|
||||
+
|
||||
+ memcpy(tmp, ((char *)&l_buf) + LIMB_BYTE_SIZE - delta, delta);
|
||||
+ tmp += delta;
|
||||
+ } else {
|
||||
+ memcpy(tmp, &l_buf, LIMB_BYTE_SIZE);
|
||||
+ tmp += LIMB_BYTE_SIZE;
|
||||
+ }
|
||||
+ }
|
||||
+ ret = num;
|
||||
+
|
||||
+ err:
|
||||
+ OPENSSL_free(l_im);
|
||||
+ OPENSSL_free(l_mul);
|
||||
+ OPENSSL_free(l_mod);
|
||||
+ OPENSSL_free(l_tmp);
|
||||
+ OPENSSL_free(l_ret);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt
|
||||
index 9f91a4a811..ba3a46d5b9 100644
|
||||
--- a/crypto/err/openssl.txt
|
||||
+++ b/crypto/err/openssl.txt
|
||||
@@ -1,4 +1,4 @@
|
||||
-# Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+# Copyright 1999-2023 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
@@ -232,6 +232,7 @@ BN_F_BN_RSHIFT:146:BN_rshift
|
||||
BN_F_BN_SET_WORDS:144:bn_set_words
|
||||
BN_F_BN_STACK_PUSH:148:BN_STACK_push
|
||||
BN_F_BN_USUB:115:BN_usub
|
||||
+BN_F_OSSL_BN_RSA_DO_UNBLIND:151:ossl_bn_rsa_do_unblind
|
||||
BUF_F_BUF_MEM_GROW:100:BUF_MEM_grow
|
||||
BUF_F_BUF_MEM_GROW_CLEAN:105:BUF_MEM_grow_clean
|
||||
BUF_F_BUF_MEM_NEW:101:BUF_MEM_new
|
||||
diff --git a/crypto/rsa/rsa_ossl.c b/crypto/rsa/rsa_ossl.c
|
||||
index b52a66f6a6..6c3c0cf78d 100644
|
||||
--- a/crypto/rsa/rsa_ossl.c
|
||||
+++ b/crypto/rsa/rsa_ossl.c
|
||||
@@ -465,11 +465,20 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,
|
||||
BN_free(d);
|
||||
}
|
||||
|
||||
- if (blinding)
|
||||
- if (!rsa_blinding_invert(blinding, ret, unblind, ctx))
|
||||
+ if (blinding) {
|
||||
+ /*
|
||||
+ * ossl_bn_rsa_do_unblind() combines blinding inversion and
|
||||
+ * 0-padded BN BE serialization
|
||||
+ */
|
||||
+ j = ossl_bn_rsa_do_unblind(ret, blinding, unblind, rsa->n, ctx,
|
||||
+ buf, num);
|
||||
+ if (j == 0)
|
||||
goto err;
|
||||
-
|
||||
- j = BN_bn2binpad(ret, buf, num);
|
||||
+ } else {
|
||||
+ j = BN_bn2binpad(ret, buf, num);
|
||||
+ if (j < 0)
|
||||
+ goto err;
|
||||
+ }
|
||||
|
||||
switch (padding) {
|
||||
case RSA_PKCS1_PADDING:
|
||||
diff --git a/include/crypto/bn.h b/include/crypto/bn.h
|
||||
index 60afda1dad..b5f36fb25a 100644
|
||||
--- a/include/crypto/bn.h
|
||||
+++ b/include/crypto/bn.h
|
||||
@@ -86,5 +86,10 @@ int bn_lshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n);
|
||||
int bn_rshift_fixed_top(BIGNUM *r, const BIGNUM *a, int n);
|
||||
int bn_div_fixed_top(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
|
||||
const BIGNUM *d, BN_CTX *ctx);
|
||||
+int ossl_bn_rsa_do_unblind(const BIGNUM *intermediate,
|
||||
+ const BN_BLINDING *blinding,
|
||||
+ const BIGNUM *possible_arg2,
|
||||
+ const BIGNUM *to_mod, BN_CTX *ctx,
|
||||
+ unsigned char *buf, int num);
|
||||
|
||||
#endif
|
||||
diff --git a/include/openssl/bnerr.h b/include/openssl/bnerr.h
|
||||
index 9f3c7cfaab..a0752cea52 100644
|
||||
--- a/include/openssl/bnerr.h
|
||||
+++ b/include/openssl/bnerr.h
|
||||
@@ -72,6 +72,7 @@ int ERR_load_BN_strings(void);
|
||||
# define BN_F_BN_SET_WORDS 144
|
||||
# define BN_F_BN_STACK_PUSH 148
|
||||
# define BN_F_BN_USUB 115
|
||||
+# define BN_F_OSSL_BN_RSA_DO_UNBLIND 151
|
||||
|
||||
/*
|
||||
* BN reason codes.
|
||||
--
|
||||
2.34.1
|
@ -1,77 +0,0 @@
|
||||
diff -Naur a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c
|
||||
--- a/crypto/dh/dh_check.c 2023-07-25 19:25:47.628975754 +0800
|
||||
+++ b/crypto/dh/dh_check.c 2023-07-25 19:22:41.934923083 +0800
|
||||
@@ -101,6 +101,12 @@
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *t1 = NULL, *t2 = NULL;
|
||||
|
||||
+ /* Don't do any checks at all with an excessively large modulus */
|
||||
+ if (BN_num_bits(dh->p) > OPENSSL_DH_CHECK_MAX_MODULUS_BITS) {
|
||||
+ DHerr(DH_F_DH_CHECK, DH_R_MODULUS_TOO_LARGE);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
if (!DH_check_params(dh, ret))
|
||||
return 0;
|
||||
|
||||
diff -Naur a/crypto/dh/dh_err.c b/crypto/dh/dh_err.c
|
||||
--- a/crypto/dh/dh_err.c 2023-07-25 19:25:47.628975754 +0800
|
||||
+++ b/crypto/dh/dh_err.c 2023-07-25 19:22:41.934923083 +0800
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
- * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+ * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -18,6 +18,7 @@
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DHPARAMS_PRINT_FP, 0), "DHparams_print_fp"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_BUILTIN_GENPARAMS, 0),
|
||||
"dh_builtin_genparams"},
|
||||
+ {ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK, 0), "DH_check"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_EX, 0), "DH_check_ex"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_PARAMS_EX, 0), "DH_check_params_ex"},
|
||||
{ERR_PACK(ERR_LIB_DH, DH_F_DH_CHECK_PUB_KEY_EX, 0), "DH_check_pub_key_ex"},
|
||||
diff -Naur a/crypto/err/openssl.txt b/crypto/err/openssl.txt
|
||||
--- a/crypto/err/openssl.txt 2023-07-25 19:25:47.632975799 +0800
|
||||
+++ b/crypto/err/openssl.txt 2023-07-25 19:22:41.938923126 +0800
|
||||
@@ -402,6 +402,7 @@
|
||||
DH_F_COMPUTE_KEY:102:compute_key
|
||||
DH_F_DHPARAMS_PRINT_FP:101:DHparams_print_fp
|
||||
DH_F_DH_BUILTIN_GENPARAMS:106:dh_builtin_genparams
|
||||
+DH_F_DH_CHECK:126:DH_check
|
||||
DH_F_DH_CHECK_EX:121:DH_check_ex
|
||||
DH_F_DH_CHECK_PARAMS_EX:122:DH_check_params_ex
|
||||
DH_F_DH_CHECK_PUB_KEY_EX:123:DH_check_pub_key_ex
|
||||
diff -Naur a/include/openssl/dherr.h b/include/openssl/dherr.h
|
||||
--- a/include/openssl/dherr.h 2023-07-25 19:25:47.668976201 +0800
|
||||
+++ b/include/openssl/dherr.h 2023-07-25 19:22:41.978923558 +0800
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Generated by util/mkerr.pl DO NOT EDIT
|
||||
- * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
+ * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the OpenSSL license (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -31,6 +31,7 @@
|
||||
# define DH_F_DHPARAMS_PRINT_FP 101
|
||||
# define DH_F_DH_BUILTIN_GENPARAMS 106
|
||||
# define DH_F_DH_CHECK_EX 121
|
||||
+# define DH_F_DH_CHECK 126
|
||||
# define DH_F_DH_CHECK_PARAMS_EX 122
|
||||
# define DH_F_DH_CHECK_PUB_KEY_EX 123
|
||||
# define DH_F_DH_CMS_DECRYPT 114
|
||||
diff -Naur a/include/openssl/dh.h b/include/openssl/dh.h
|
||||
--- a/include/openssl/dh.h 2023-07-25 19:25:47.668976201 +0800
|
||||
+++ b/include/openssl/dh.h 2023-07-25 19:22:41.978923558 +0800
|
||||
@@ -29,6 +29,9 @@
|
||||
# ifndef OPENSSL_DH_MAX_MODULUS_BITS
|
||||
# define OPENSSL_DH_MAX_MODULUS_BITS 10000
|
||||
# endif
|
||||
+# ifndef OPENSSL_DH_CHECK_MAX_MODULUS_BITS
|
||||
+# define OPENSSL_DH_CHECK_MAX_MODULUS_BITS 32768
|
||||
+# endif
|
||||
|
||||
# define OPENSSL_DH_FIPS_MIN_MODULUS_BITS 1024
|
@ -1,28 +0,0 @@
|
||||
diff -Naur a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c
|
||||
--- a/crypto/dh/dh_check.c 2023-09-01 14:52:09.746018434 +0800
|
||||
+++ b/crypto/dh/dh_check.c 2023-09-01 15:06:12.055519115 +0800
|
||||
@@ -97,7 +97,7 @@
|
||||
|
||||
int DH_check(const DH *dh, int *ret)
|
||||
{
|
||||
- int ok = 0, r;
|
||||
+ int ok = 0, r, q_good = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *t1 = NULL, *t2 = NULL;
|
||||
|
||||
@@ -113,7 +113,14 @@
|
||||
if (t2 == NULL)
|
||||
goto err;
|
||||
|
||||
- if (dh->q) {
|
||||
+ if (dh->q != NULL) {
|
||||
+ if (BN_ucmp(dh->p, dh->q) > 0)
|
||||
+ q_good = 1;
|
||||
+ else
|
||||
+ *ret |= DH_CHECK_INVALID_Q_VALUE;
|
||||
+ }
|
||||
+
|
||||
+ if (q_good) {
|
||||
if (BN_cmp(dh->g, BN_value_one()) <= 0)
|
||||
*ret |= DH_NOT_SUITABLE_GENERATOR;
|
||||
else if (BN_cmp(dh->g, dh->p) >= 0)
|
@ -1,6 +1,6 @@
|
||||
diff -Naur a/crypto/pkcs12/p12_add.c b/crypto/pkcs12/p12_add.c
|
||||
--- a/crypto/pkcs12/p12_add.c 2024-02-04 10:55:19.252070922 +0800
|
||||
+++ b/crypto/pkcs12/p12_add.c 2024-02-04 10:53:27.906106687 +0800
|
||||
--- a/crypto/pkcs12/p12_add.c 2024-02-02 15:39:27.287368573 +0800
|
||||
+++ b/crypto/pkcs12/p12_add.c 2024-02-02 15:38:30.271860109 +0800
|
||||
@@ -76,6 +76,12 @@
|
||||
PKCS12_R_CONTENT_TYPE_NOT_DATA);
|
||||
return NULL;
|
||||
@ -14,20 +14,19 @@ diff -Naur a/crypto/pkcs12/p12_add.c b/crypto/pkcs12/p12_add.c
|
||||
return ASN1_item_unpack(p7->d.data, ASN1_ITEM_rptr(PKCS12_SAFEBAGS));
|
||||
}
|
||||
|
||||
@@ -132,6 +138,12 @@
|
||||
@@ -132,6 +138,11 @@
|
||||
{
|
||||
if (!PKCS7_type_is_encrypted(p7))
|
||||
return NULL;
|
||||
+
|
||||
+ if (p7->d.data == NULL) {
|
||||
+ PKCS12err(PKCS12_F_PKCS12_UNPACK_P7DATA, PKCS12_R_DECODE_ERROR);
|
||||
+ if (p7->d.encrypted == NULL) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
return PKCS12_item_decrypt_d2i(p7->d.encrypted->enc_data->algorithm,
|
||||
ASN1_ITEM_rptr(PKCS12_SAFEBAGS),
|
||||
pass, passlen,
|
||||
@@ -159,6 +171,11 @@
|
||||
@@ -159,6 +170,11 @@
|
||||
PKCS12_R_CONTENT_TYPE_NOT_DATA);
|
||||
return NULL;
|
||||
}
|
||||
@ -40,8 +39,8 @@ diff -Naur a/crypto/pkcs12/p12_add.c b/crypto/pkcs12/p12_add.c
|
||||
ASN1_ITEM_rptr(PKCS12_AUTHSAFES));
|
||||
}
|
||||
diff -Naur a/crypto/pkcs12/p12_mutl.c b/crypto/pkcs12/p12_mutl.c
|
||||
--- a/crypto/pkcs12/p12_mutl.c 2024-02-04 10:55:19.252070922 +0800
|
||||
+++ b/crypto/pkcs12/p12_mutl.c 2024-02-04 10:53:27.906106687 +0800
|
||||
--- a/crypto/pkcs12/p12_mutl.c 2024-02-02 15:39:27.287368573 +0800
|
||||
+++ b/crypto/pkcs12/p12_mutl.c 2024-02-02 15:38:30.271860109 +0800
|
||||
@@ -93,6 +93,11 @@
|
||||
return 0;
|
||||
}
|
||||
@ -55,8 +54,8 @@ diff -Naur a/crypto/pkcs12/p12_mutl.c b/crypto/pkcs12/p12_mutl.c
|
||||
saltlen = p12->mac->salt->length;
|
||||
if (!p12->mac->iter)
|
||||
diff -Naur a/crypto/pkcs12/p12_npas.c b/crypto/pkcs12/p12_npas.c
|
||||
--- a/crypto/pkcs12/p12_npas.c 2024-02-04 10:55:19.252070922 +0800
|
||||
+++ b/crypto/pkcs12/p12_npas.c 2024-02-04 10:53:27.906106687 +0800
|
||||
--- a/crypto/pkcs12/p12_npas.c 2024-02-02 15:39:27.287368573 +0800
|
||||
+++ b/crypto/pkcs12/p12_npas.c 2024-02-02 15:38:30.271860109 +0800
|
||||
@@ -78,8 +78,9 @@
|
||||
bags = PKCS12_unpack_p7data(p7);
|
||||
} else if (bagnid == NID_pkcs7_encrypted) {
|
||||
@ -70,9 +69,9 @@ diff -Naur a/crypto/pkcs12/p12_npas.c b/crypto/pkcs12/p12_npas.c
|
||||
} else {
|
||||
continue;
|
||||
diff -Naur a/crypto/pkcs7/pk7_mime.c b/crypto/pkcs7/pk7_mime.c
|
||||
--- a/crypto/pkcs7/pk7_mime.c 2024-02-04 10:55:19.245070861 +0800
|
||||
+++ b/crypto/pkcs7/pk7_mime.c 2024-02-04 10:53:27.898106618 +0800
|
||||
@@ -30,11 +30,14 @@
|
||||
--- a/crypto/pkcs7/pk7_mime.c 2024-02-02 15:39:27.280368511 +0800
|
||||
+++ b/crypto/pkcs7/pk7_mime.c 2024-02-02 15:38:30.263860038 +0800
|
||||
@@ -30,10 +30,14 @@
|
||||
{
|
||||
STACK_OF(X509_ALGOR) *mdalgs;
|
||||
int ctype_nid = OBJ_obj2nid(p7->type);
|
||||
@ -85,8 +84,7 @@ diff -Naur a/crypto/pkcs7/pk7_mime.c b/crypto/pkcs7/pk7_mime.c
|
||||
- else
|
||||
+ } else {
|
||||
mdalgs = NULL;
|
||||
-
|
||||
+ }
|
||||
flags ^= SMIME_OLDMIME;
|
||||
|
||||
return SMIME_write_ASN1(bio, (ASN1_VALUE *)p7, data, flags,
|
||||
flags ^= SMIME_OLDMIME;
|
||||
|
||||
|
@ -0,0 +1,74 @@
|
||||
From fa3d5b8af929c296f4d684345dedf1e2b4b390e2 Mon Sep 17 00:00:00 2001
|
||||
From: gaoyusong <gaoyusong2@huawei.com>
|
||||
Date: Fri, 30 Sep 2022 12:10:15 +0800
|
||||
Subject: [PATCH] PKCS7 sign and verify support SM2 algorithm
|
||||
|
||||
Signed-off-by: Huaxin Lu <luhuaxin1@huawei.com>
|
||||
---
|
||||
crypto/pkcs7/pk7_doit.c | 23 +++++++++++++++++++++--
|
||||
crypto/sm2/sm2_pmeth.c | 1 +
|
||||
2 files changed, 22 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/crypto/pkcs7/pk7_doit.c b/crypto/pkcs7/pk7_doit.c
|
||||
index f63fbc5..916a35a 100644
|
||||
--- a/crypto/pkcs7/pk7_doit.c
|
||||
+++ b/crypto/pkcs7/pk7_doit.c
|
||||
@@ -946,6 +946,9 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
|
||||
STACK_OF(X509_ATTRIBUTE) *sk;
|
||||
BIO *btmp;
|
||||
EVP_PKEY *pkey;
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ EVP_PKEY_CTX *pctx = NULL;
|
||||
+#endif
|
||||
|
||||
mdc_tmp = EVP_MD_CTX_new();
|
||||
if (mdc_tmp == NULL) {
|
||||
@@ -1013,7 +1016,19 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
|
||||
goto err;
|
||||
}
|
||||
|
||||
- if (!EVP_VerifyInit_ex(mdc_tmp, EVP_get_digestbynid(md_type), NULL))
|
||||
+ pkey = X509_get0_pubkey(x509);
|
||||
+ if (!pkey) {
|
||||
+ ret = -1;
|
||||
+ goto err;
|
||||
+ }
|
||||
+
|
||||
+ ret =
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ EVP_PKEY_is_sm2(pkey) ?
|
||||
+ EVP_DigestVerifyInit(mdc_tmp, &pctx, EVP_get_digestbynid(md_type), NULL, pkey) :
|
||||
+#endif
|
||||
+ EVP_VerifyInit_ex(mdc_tmp, EVP_get_digestbynid(md_type), NULL);
|
||||
+ if (!ret)
|
||||
goto err;
|
||||
|
||||
alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
|
||||
@@ -1036,7 +1051,11 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
|
||||
goto err;
|
||||
}
|
||||
|
||||
- i = EVP_VerifyFinal(mdc_tmp, os->data, os->length, pkey);
|
||||
+ i =
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ EVP_PKEY_is_sm2(pkey) ? EVP_DigestVerifyFinal(mdc_tmp, os->data, os->length) :
|
||||
+#endif
|
||||
+ EVP_VerifyFinal(mdc_tmp, os->data, os->length, pkey);
|
||||
if (i <= 0) {
|
||||
PKCS7err(PKCS7_F_PKCS7_SIGNATUREVERIFY, PKCS7_R_SIGNATURE_FAILURE);
|
||||
ret = -1;
|
||||
diff --git a/crypto/sm2/sm2_pmeth.c b/crypto/sm2/sm2_pmeth.c
|
||||
index 1998812..53cdbe9 100644
|
||||
--- a/crypto/sm2/sm2_pmeth.c
|
||||
+++ b/crypto/sm2/sm2_pmeth.c
|
||||
@@ -221,6 +221,7 @@ static int pkey_sm2_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
|
||||
return 1;
|
||||
|
||||
case EVP_PKEY_CTRL_DIGESTINIT:
|
||||
+ case EVP_PKEY_CTRL_PKCS7_SIGN:
|
||||
/* nothing to be inited, this is to suppress the error... */
|
||||
return 1;
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
@ -0,0 +1,621 @@
|
||||
From 3f0898b2aea424f18f58a182803478f25548674e Mon Sep 17 00:00:00 2001
|
||||
From: Xu Yizhou <xuyizhou1@huawei.com>
|
||||
Date: Wed, 2 Nov 2022 11:13:07 +0800
|
||||
Subject: [PATCH 3/3] SM4 XTS optimization for ARM by HW instruction
|
||||
|
||||
This patch implements the SM4 XTS optimization for ARM processor,
|
||||
using SM4 HW instruction, which is an optional feature of
|
||||
crypto extension for aarch64 V8.
|
||||
|
||||
Signed-off-by: Xu Yizhou <xuyizhou1@huawei.com>
|
||||
---
|
||||
crypto/evp/e_sm4.c | 28 ++
|
||||
crypto/sm4/asm/sm4-armv8.pl | 498 +++++++++++++++++++++++++++++++++-
|
||||
include/crypto/sm4_platform.h | 14 +
|
||||
3 files changed, 537 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/crypto/evp/e_sm4.c b/crypto/evp/e_sm4.c
|
||||
index eaa5ba0..da4dbd3 100644
|
||||
--- a/crypto/evp/e_sm4.c
|
||||
+++ b/crypto/evp/e_sm4.c
|
||||
@@ -281,6 +281,34 @@ static int sm4_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
|
||||
const int bytes = EVP_CIPHER_CTX_key_length(ctx) / 2;
|
||||
xctx->stream_gb = NULL;
|
||||
xctx->stream = NULL;
|
||||
+#ifdef HWSM4_CAPABLE
|
||||
+ if (HWSM4_CAPABLE) {
|
||||
+ if (enc) {
|
||||
+ HWSM4_set_encrypt_key(key, &xctx->ks1.ks);
|
||||
+ xctx->xts.block1 = (block128_f) HWSM4_encrypt;
|
||||
+# ifdef HWSM4_xts_encrypt_gb
|
||||
+ xctx->stream_gb = HWSM4_xts_encrypt_gb;
|
||||
+# endif
|
||||
+# ifdef HWSM4_xts_encrypt
|
||||
+ xctx->stream = HWSM4_xts_encrypt;
|
||||
+# endif
|
||||
+ } else {
|
||||
+ HWSM4_set_decrypt_key(key, &xctx->ks1.ks);
|
||||
+ xctx->xts.block1 = (block128_f) HWSM4_decrypt;
|
||||
+# ifdef HWSM4_xts_decrypt_gb
|
||||
+ xctx->stream_gb = HWSM4_xts_decrypt_gb;
|
||||
+# endif
|
||||
+# ifdef HWSM4_xts_decrypt
|
||||
+ xctx->stream = HWSM4_xts_decrypt;
|
||||
+# endif
|
||||
+ }
|
||||
+ HWSM4_set_encrypt_key(key + bytes, &xctx->ks2.ks);
|
||||
+ xctx->xts.block2 = (block128_f) HWSM4_encrypt;
|
||||
+
|
||||
+ xctx->xts.key1 = &xctx->ks1;
|
||||
+ break;
|
||||
+ } else
|
||||
+#endif
|
||||
#ifdef VPSM4_EX_CAPABLE
|
||||
if (VPSM4_EX_CAPABLE) {
|
||||
if (enc) {
|
||||
diff --git a/crypto/sm4/asm/sm4-armv8.pl b/crypto/sm4/asm/sm4-armv8.pl
|
||||
index dbacad2..923c1c0 100644
|
||||
--- a/crypto/sm4/asm/sm4-armv8.pl
|
||||
+++ b/crypto/sm4/asm/sm4-armv8.pl
|
||||
@@ -11,9 +11,9 @@
|
||||
# Oct 2021
|
||||
#
|
||||
|
||||
-# $output is the last argument if it looks like a file (it has an extension)
|
||||
+# $outut is the last argument if it looks like a file (it has an extension)
|
||||
# $flavour is the first argument if it doesn't look like a file
|
||||
-$output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
|
||||
+$outut = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
|
||||
$flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
|
||||
|
||||
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
@@ -21,7 +21,7 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
( $xlate="${dir}../../perlasm/arm-xlate.pl" and -f $xlate) or
|
||||
die "can't locate arm-xlate.pl";
|
||||
|
||||
-open OUT,"| \"$^X\" $xlate $flavour \"$output\""
|
||||
+open OUT,"| \"$^X\" $xlate $flavour \"$outut\""
|
||||
or die "can't call $xlate: $!";
|
||||
*STDOUT=*OUT;
|
||||
|
||||
@@ -110,6 +110,120 @@ $code.=<<___;
|
||||
___
|
||||
}
|
||||
|
||||
+sub mov_reg_to_vec() {
|
||||
+ my $src0 = shift;
|
||||
+ my $src1 = shift;
|
||||
+ my $desv = shift;
|
||||
+$code.=<<___;
|
||||
+ mov $desv.d[0],$src0
|
||||
+ mov $desv.d[1],$src1
|
||||
+#ifdef __ARMEB__
|
||||
+ rev32 $desv.16b,$desv.16b
|
||||
+#endif
|
||||
+___
|
||||
+}
|
||||
+
|
||||
+sub mov_vec_to_reg() {
|
||||
+ my $srcv = shift;
|
||||
+ my $des0 = shift;
|
||||
+ my $des1 = shift;
|
||||
+$code.=<<___;
|
||||
+ mov $des0,$srcv.d[0]
|
||||
+ mov $des1,$srcv.d[1]
|
||||
+___
|
||||
+}
|
||||
+
|
||||
+sub compute_tweak() {
|
||||
+ my $src0 = shift;
|
||||
+ my $src1 = shift;
|
||||
+ my $des0 = shift;
|
||||
+ my $des1 = shift;
|
||||
+ my $tmp0 = shift;
|
||||
+ my $tmp1 = shift;
|
||||
+ my $magic = shift;
|
||||
+$code.=<<___;
|
||||
+ extr x$tmp1,$src1,$src1,#32
|
||||
+ extr $des1,$src1,$src0,#63
|
||||
+ and w$tmp0,w$magic,w$tmp1,asr#31
|
||||
+ eor $des0,x$tmp0,$src0,lsl#1
|
||||
+___
|
||||
+}
|
||||
+
|
||||
+sub compute_tweak_vec() {
|
||||
+ my $src = shift;
|
||||
+ my $des = shift;
|
||||
+ my $tmp0 = shift;
|
||||
+ my $tmp1 = shift;
|
||||
+ my $magic = shift;
|
||||
+ &rbit($tmp1,$src);
|
||||
+$code.=<<___;
|
||||
+ shl $des.16b, $tmp1.16b, #1
|
||||
+ ext $tmp0.16b, $tmp1.16b, $tmp1.16b,#15
|
||||
+ ushr $tmp0.16b, $tmp0.16b, #7
|
||||
+ mul $tmp0.16b, $tmp0.16b, $magic.16b
|
||||
+ eor $des.16b, $des.16b, $tmp0.16b
|
||||
+___
|
||||
+ &rbit($des,$des);
|
||||
+}
|
||||
+
|
||||
+sub mov_en_to_enc(){
|
||||
+ my $en = shift;
|
||||
+ my $enc = shift;
|
||||
+ if ($en eq "en") {
|
||||
+$code.=<<___;
|
||||
+ mov $enc,1
|
||||
+___
|
||||
+ } else {
|
||||
+$code.=<<___;
|
||||
+ mov $enc,0
|
||||
+___
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+sub rbit() {
|
||||
+ my $dst = shift;
|
||||
+ my $src = shift;
|
||||
+
|
||||
+ if ($src and ("$src" ne "$dst")) {
|
||||
+ if ($standard eq "_gb") {
|
||||
+$code.=<<___;
|
||||
+ rbit $dst.16b,$src.16b
|
||||
+___
|
||||
+ } else {
|
||||
+$code.=<<___;
|
||||
+ mov $dst.16b,$src.16b
|
||||
+___
|
||||
+ }
|
||||
+ } else {
|
||||
+ if ($standard eq "_gb") {
|
||||
+$code.=<<___;
|
||||
+ rbit $dst.16b,$src.16b
|
||||
+___
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+sub rev32_armeb() {
|
||||
+ my $dst = shift;
|
||||
+ my $src = shift;
|
||||
+
|
||||
+ if ($src and ("$src" ne "$dst")) {
|
||||
+$code.=<<___;
|
||||
+#ifdef __ARMEB__
|
||||
+ rev32 $dst.16b,$src.16b
|
||||
+#else
|
||||
+ mov $dst.16b,$src.16b
|
||||
+#endif
|
||||
+___
|
||||
+ } else {
|
||||
+$code.=<<___;
|
||||
+#ifdef __ARMEB__
|
||||
+ rev32 $dst.16b,$dst.16b
|
||||
+#endif
|
||||
+___
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
$code=<<___;
|
||||
#include "arm_arch.h"
|
||||
.arch armv8-a+crypto
|
||||
@@ -595,6 +709,384 @@ $code.=<<___;
|
||||
.size ${prefix}_ctr32_encrypt_blocks,.-${prefix}_ctr32_encrypt_blocks
|
||||
___
|
||||
}}}
|
||||
+
|
||||
+
|
||||
+{{{
|
||||
+my ($inp,$out,$len,$rk1,$rk2,$ivp)=map("x$_",(0..5));
|
||||
+my ($blocks)=("x2");
|
||||
+my ($enc)=("x6");
|
||||
+my ($remain)=("x7");
|
||||
+my @twx=map("x$_",(9..24));
|
||||
+my $lastBlk=("x25");
|
||||
+
|
||||
+my @tweak=map("v$_",(8..15));
|
||||
+my @dat=map("v$_",(16..23));
|
||||
+my $lastTweak=("v24");
|
||||
+
|
||||
+# x/w/v/q registers for compute tweak
|
||||
+my ($magic)=("8");
|
||||
+my ($tmp0,$tmp1)=("26","27");
|
||||
+my ($qMagic,$vMagic)=("q25","v25");
|
||||
+my ($vTmp0,$vTmp1)=("v26","v27");
|
||||
+
|
||||
+sub gen_xts_do_cipher() {
|
||||
+$code.=<<___;
|
||||
+.globl ${prefix}_xts_do_cipher${standard}
|
||||
+.type ${prefix}_xts_do_cipher${standard},%function
|
||||
+.align 5
|
||||
+${prefix}_xts_do_cipher${standard}:
|
||||
+ mov w$magic,0x87
|
||||
+ ldr $qMagic, =0x01010101010101010101010101010187
|
||||
+ // used to encrypt the XORed plaintext blocks
|
||||
+ ld1 {@rks[0].4s,@rks[1].4s,@rks[2].4s,@rks[3].4s},[$rk2],#64
|
||||
+ ld1 {@rks[4].4s,@rks[5].4s,@rks[6].4s,@rks[7].4s},[$rk2]
|
||||
+ ld1 {@tweak[0].4s}, [$ivp]
|
||||
+___
|
||||
+ &rev32(@tweak[0],@tweak[0]);
|
||||
+ &enc_blk(@tweak[0]);
|
||||
+ &rev32(@tweak[0],@tweak[0]);
|
||||
+$code.=<<___;
|
||||
+ // used to encrypt the initial vector to yield the initial tweak
|
||||
+ ld1 {@rks[0].4s,@rks[1].4s,@rks[2].4s,@rks[3].4s},[$rk1],#64
|
||||
+ ld1 {@rks[4].4s,@rks[5].4s,@rks[6].4s,@rks[7].4s},[$rk1]
|
||||
+
|
||||
+ and $remain,$len,#0x0F
|
||||
+ // convert length into blocks
|
||||
+ lsr $blocks,$len,4
|
||||
+ cmp $blocks,#1 // $len must be at least 16
|
||||
+ b.lt 99f
|
||||
+
|
||||
+ cmp $remain,0 // if $len is a multiple of 16
|
||||
+ b.eq .xts_encrypt_blocks${standard}
|
||||
+ // if $len is not a multiple of 16
|
||||
+ subs $blocks,$blocks,#1
|
||||
+ b.eq .only_2blks_tweak${standard} // if $len is less than 32
|
||||
+
|
||||
+.xts_encrypt_blocks${standard}:
|
||||
+___
|
||||
+ &rbit(@tweak[0],@tweak[0]);
|
||||
+ &rev32_armeb(@tweak[0],@tweak[0]);
|
||||
+ &mov_vec_to_reg(@tweak[0],@twx[0],@twx[1]);
|
||||
+ &compute_tweak(@twx[0],@twx[1],@twx[2],@twx[3],$tmp0,$tmp1,$magic);
|
||||
+ &compute_tweak(@twx[2],@twx[3],@twx[4],@twx[5],$tmp0,$tmp1,$magic);
|
||||
+ &compute_tweak(@twx[4],@twx[5],@twx[6],@twx[7],$tmp0,$tmp1,$magic);
|
||||
+ &compute_tweak(@twx[6],@twx[7],@twx[8],@twx[9],$tmp0,$tmp1,$magic);
|
||||
+ &compute_tweak(@twx[8],@twx[9],@twx[10],@twx[11],$tmp0,$tmp1,$magic);
|
||||
+ &compute_tweak(@twx[10],@twx[11],@twx[12],@twx[13],$tmp0,$tmp1,$magic);
|
||||
+ &compute_tweak(@twx[12],@twx[13],@twx[14],@twx[15],$tmp0,$tmp1,$magic);
|
||||
+$code.=<<___;
|
||||
+1:
|
||||
+ cmp $blocks,#8
|
||||
+___
|
||||
+ &mov_reg_to_vec(@twx[0],@twx[1],@tweak[0]);
|
||||
+ &compute_tweak(@twx[14],@twx[15],@twx[0],@twx[1],$tmp0,$tmp1,$magic);
|
||||
+ &mov_reg_to_vec(@twx[2],@twx[3],@tweak[1]);
|
||||
+ &compute_tweak(@twx[0],@twx[1],@twx[2],@twx[3],$tmp0,$tmp1,$magic);
|
||||
+ &mov_reg_to_vec(@twx[4],@twx[5],@tweak[2]);
|
||||
+ &compute_tweak(@twx[2],@twx[3],@twx[4],@twx[5],$tmp0,$tmp1,$magic);
|
||||
+ &mov_reg_to_vec(@twx[6],@twx[7],@tweak[3]);
|
||||
+ &compute_tweak(@twx[4],@twx[5],@twx[6],@twx[7],$tmp0,$tmp1,$magic);
|
||||
+ &mov_reg_to_vec(@twx[8],@twx[9],@tweak[4]);
|
||||
+ &compute_tweak(@twx[6],@twx[7],@twx[8],@twx[9],$tmp0,$tmp1,$magic);
|
||||
+ &mov_reg_to_vec(@twx[10],@twx[11],@tweak[5]);
|
||||
+ &compute_tweak(@twx[8],@twx[9],@twx[10],@twx[11],$tmp0,$tmp1,$magic);
|
||||
+ &mov_reg_to_vec(@twx[12],@twx[13],@tweak[6]);
|
||||
+ &compute_tweak(@twx[10],@twx[11],@twx[12],@twx[13],$tmp0,$tmp1,$magic);
|
||||
+ &mov_reg_to_vec(@twx[14],@twx[15],@tweak[7]);
|
||||
+ &compute_tweak(@twx[12],@twx[13],@twx[14],@twx[15],$tmp0,$tmp1,$magic);
|
||||
+$code.=<<___;
|
||||
+ b.lt 2f
|
||||
+ ld1 {@dat[0].4s,@dat[1].4s,@dat[2].4s,@dat[3].4s},[$inp],#64
|
||||
+___
|
||||
+ &rbit(@tweak[0],@tweak[0]);
|
||||
+ &rbit(@tweak[1],@tweak[1]);
|
||||
+ &rbit(@tweak[2],@tweak[2]);
|
||||
+ &rbit(@tweak[3],@tweak[3]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[0].16b
|
||||
+ eor @dat[1].16b, @dat[1].16b, @tweak[1].16b
|
||||
+ eor @dat[2].16b, @dat[2].16b, @tweak[2].16b
|
||||
+ eor @dat[3].16b, @dat[3].16b, @tweak[3].16b
|
||||
+ ld1 {@dat[4].4s,@dat[5].4s,@dat[6].4s,@dat[7].4s},[$inp],#64
|
||||
+___
|
||||
+ &rbit(@tweak[4],@tweak[4]);
|
||||
+ &rbit(@tweak[5],@tweak[5]);
|
||||
+ &rbit(@tweak[6],@tweak[6]);
|
||||
+ &rbit(@tweak[7],@tweak[7]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[4].16b, @dat[4].16b, @tweak[4].16b
|
||||
+ eor @dat[5].16b, @dat[5].16b, @tweak[5].16b
|
||||
+ eor @dat[6].16b, @dat[6].16b, @tweak[6].16b
|
||||
+ eor @dat[7].16b, @dat[7].16b, @tweak[7].16b
|
||||
+___
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &rev32(@dat[1],@dat[1]);
|
||||
+ &rev32(@dat[2],@dat[2]);
|
||||
+ &rev32(@dat[3],@dat[3]);
|
||||
+ &rev32(@dat[4],@dat[4]);
|
||||
+ &rev32(@dat[5],@dat[5]);
|
||||
+ &rev32(@dat[6],@dat[6]);
|
||||
+ &rev32(@dat[7],@dat[7]);
|
||||
+ &enc_4blks(@dat[0],@dat[1],@dat[2],@dat[3]);
|
||||
+ &enc_4blks(@dat[4],@dat[5],@dat[6],@dat[7]);
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &rev32(@dat[1],@dat[1]);
|
||||
+ &rev32(@dat[2],@dat[2]);
|
||||
+ &rev32(@dat[3],@dat[3]);
|
||||
+ &rev32(@dat[4],@dat[4]);
|
||||
+ &rev32(@dat[5],@dat[5]);
|
||||
+ &rev32(@dat[6],@dat[6]);
|
||||
+ &rev32(@dat[7],@dat[7]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[0].16b
|
||||
+ eor @dat[1].16b, @dat[1].16b, @tweak[1].16b
|
||||
+ eor @dat[2].16b, @dat[2].16b, @tweak[2].16b
|
||||
+ eor @dat[3].16b, @dat[3].16b, @tweak[3].16b
|
||||
+ eor @dat[4].16b, @dat[4].16b, @tweak[4].16b
|
||||
+ eor @dat[5].16b, @dat[5].16b, @tweak[5].16b
|
||||
+ eor @dat[6].16b, @dat[6].16b, @tweak[6].16b
|
||||
+ eor @dat[7].16b, @dat[7].16b, @tweak[7].16b
|
||||
+
|
||||
+ // save the last tweak
|
||||
+ mov $lastTweak.16b,@tweak[7].16b
|
||||
+ st1 {@dat[0].4s,@dat[1].4s,@dat[2].4s,@dat[3].4s},[$out],#64
|
||||
+ st1 {@dat[4].4s,@dat[5].4s,@dat[6].4s,@dat[7].4s},[$out],#64
|
||||
+ subs $blocks,$blocks,#8
|
||||
+ b.eq 100f
|
||||
+ b 1b
|
||||
+2:
|
||||
+ // process 4 blocks
|
||||
+ cmp $blocks,#4
|
||||
+ b.lt 1f
|
||||
+ ld1 {@dat[0].4s,@dat[1].4s,@dat[2].4s,@dat[3].4s},[$inp],#64
|
||||
+___
|
||||
+ &rbit(@tweak[0],@tweak[0]);
|
||||
+ &rbit(@tweak[1],@tweak[1]);
|
||||
+ &rbit(@tweak[2],@tweak[2]);
|
||||
+ &rbit(@tweak[3],@tweak[3]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[0].16b
|
||||
+ eor @dat[1].16b, @dat[1].16b, @tweak[1].16b
|
||||
+ eor @dat[2].16b, @dat[2].16b, @tweak[2].16b
|
||||
+ eor @dat[3].16b, @dat[3].16b, @tweak[3].16b
|
||||
+___
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &rev32(@dat[1],@dat[1]);
|
||||
+ &rev32(@dat[2],@dat[2]);
|
||||
+ &rev32(@dat[3],@dat[3]);
|
||||
+ &enc_4blks(@dat[0],@dat[1],@dat[2],@dat[3]);
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &rev32(@dat[1],@dat[1]);
|
||||
+ &rev32(@dat[2],@dat[2]);
|
||||
+ &rev32(@dat[3],@dat[3]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[0].16b
|
||||
+ eor @dat[1].16b, @dat[1].16b, @tweak[1].16b
|
||||
+ eor @dat[2].16b, @dat[2].16b, @tweak[2].16b
|
||||
+ eor @dat[3].16b, @dat[3].16b, @tweak[3].16b
|
||||
+ st1 {@dat[0].4s,@dat[1].4s,@dat[2].4s,@dat[3].4s},[$out],#64
|
||||
+ sub $blocks,$blocks,#4
|
||||
+ mov @tweak[0].16b,@tweak[4].16b
|
||||
+ mov @tweak[1].16b,@tweak[5].16b
|
||||
+ mov @tweak[2].16b,@tweak[6].16b
|
||||
+ // save the last tweak
|
||||
+ mov $lastTweak.16b,@tweak[3].16b
|
||||
+1:
|
||||
+ // process last block
|
||||
+ cmp $blocks,#1
|
||||
+ b.lt 100f
|
||||
+ b.gt 1f
|
||||
+ ld1 {@dat[0].4s},[$inp],#16
|
||||
+___
|
||||
+ &rbit(@tweak[0],@tweak[0]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[0].16b
|
||||
+___
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &enc_blk(@dat[0]);
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[0].16b
|
||||
+ st1 {@dat[0].4s},[$out],#16
|
||||
+ // save the last tweak
|
||||
+ mov $lastTweak.16b,@tweak[0].16b
|
||||
+ b 100f
|
||||
+1: // process last 2 blocks
|
||||
+ cmp $blocks,#2
|
||||
+ b.gt 1f
|
||||
+ ld1 {@dat[0].4s,@dat[1].4s},[$inp],#32
|
||||
+___
|
||||
+ &rbit(@tweak[0],@tweak[0]);
|
||||
+ &rbit(@tweak[1],@tweak[1]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[0].16b
|
||||
+ eor @dat[1].16b, @dat[1].16b, @tweak[1].16b
|
||||
+___
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &rev32(@dat[1],@dat[1]);
|
||||
+ &enc_4blks(@dat[0],@dat[1],@dat[2],@dat[3]);
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &rev32(@dat[1],@dat[1]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[0].16b
|
||||
+ eor @dat[1].16b, @dat[1].16b, @tweak[1].16b
|
||||
+ st1 {@dat[0].4s,@dat[1].4s},[$out],#32
|
||||
+ // save the last tweak
|
||||
+ mov $lastTweak.16b,@tweak[1].16b
|
||||
+ b 100f
|
||||
+1: // process last 3 blocks
|
||||
+ ld1 {@dat[0].4s,@dat[1].4s,@dat[2].4s},[$inp],#48
|
||||
+___
|
||||
+ &rbit(@tweak[0],@tweak[0]);
|
||||
+ &rbit(@tweak[1],@tweak[1]);
|
||||
+ &rbit(@tweak[2],@tweak[2]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[0].16b
|
||||
+ eor @dat[1].16b, @dat[1].16b, @tweak[1].16b
|
||||
+ eor @dat[2].16b, @dat[2].16b, @tweak[2].16b
|
||||
+___
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &rev32(@dat[1],@dat[1]);
|
||||
+ &rev32(@dat[2],@dat[2]);
|
||||
+ &enc_4blks(@dat[0],@dat[1],@dat[2],@dat[3]);
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &rev32(@dat[1],@dat[1]);
|
||||
+ &rev32(@dat[2],@dat[2]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[0].16b
|
||||
+ eor @dat[1].16b, @dat[1].16b, @tweak[1].16b
|
||||
+ eor @dat[2].16b, @dat[2].16b, @tweak[2].16b
|
||||
+ st1 {@dat[0].4s,@dat[1].4s,@dat[2].4s},[$out],#48
|
||||
+ // save the last tweak
|
||||
+ mov $lastTweak.16b,@tweak[2].16b
|
||||
+100:
|
||||
+ cmp $remain,0
|
||||
+ b.eq 99f
|
||||
+
|
||||
+// This brance calculates the last two tweaks,
|
||||
+// while the encryption/decryption length is larger than 32
|
||||
+.last_2blks_tweak${standard}:
|
||||
+___
|
||||
+ &rev32_armeb($lastTweak,$lastTweak);
|
||||
+ &compute_tweak_vec($lastTweak,@tweak[1],$vTmp0,$vTmp1,$vMagic);
|
||||
+ &compute_tweak_vec(@tweak[1],@tweak[2],$vTmp0,$vTmp1,$vMagic);
|
||||
+$code.=<<___;
|
||||
+ b .check_dec${standard}
|
||||
+
|
||||
+
|
||||
+// This brance calculates the last two tweaks,
|
||||
+// while the encryption/decryption length is less than 32, who only need two tweaks
|
||||
+.only_2blks_tweak${standard}:
|
||||
+ mov @tweak[1].16b,@tweak[0].16b
|
||||
+___
|
||||
+ &rev32_armeb(@tweak[1],@tweak[1]);
|
||||
+ &compute_tweak_vec(@tweak[1],@tweak[2],$vTmp0,$vTmp1,$vMagic);
|
||||
+$code.=<<___;
|
||||
+ b .check_dec${standard}
|
||||
+
|
||||
+
|
||||
+// Determine whether encryption or decryption is required.
|
||||
+// The last two tweaks need to be swapped for decryption.
|
||||
+.check_dec${standard}:
|
||||
+ // encryption:1 decryption:0
|
||||
+ cmp $enc,1
|
||||
+ b.eq .prcess_last_2blks${standard}
|
||||
+ mov $vTmp0.16B,@tweak[1].16b
|
||||
+ mov @tweak[1].16B,@tweak[2].16b
|
||||
+ mov @tweak[2].16B,$vTmp0.16b
|
||||
+
|
||||
+.prcess_last_2blks${standard}:
|
||||
+___
|
||||
+ &rev32_armeb(@tweak[1],@tweak[1]);
|
||||
+ &rev32_armeb(@tweak[2],@tweak[2]);
|
||||
+$code.=<<___;
|
||||
+ ld1 {@dat[0].4s},[$inp],#16
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[1].16b
|
||||
+___
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &enc_blk(@dat[0]);
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[1].16b
|
||||
+ st1 {@dat[0].4s},[$out],#16
|
||||
+
|
||||
+ sub $lastBlk,$out,16
|
||||
+ .loop${standard}:
|
||||
+ subs $remain,$remain,1
|
||||
+ ldrb w$tmp0,[$lastBlk,$remain]
|
||||
+ ldrb w$tmp1,[$inp,$remain]
|
||||
+ strb w$tmp1,[$lastBlk,$remain]
|
||||
+ strb w$tmp0,[$out,$remain]
|
||||
+ b.gt .loop${standard}
|
||||
+ ld1 {@dat[0].4s}, [$lastBlk]
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[2].16b
|
||||
+___
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+ &enc_blk(@dat[0]);
|
||||
+ &rev32(@dat[0],@dat[0]);
|
||||
+$code.=<<___;
|
||||
+ eor @dat[0].16b, @dat[0].16b, @tweak[2].16b
|
||||
+ st1 {@dat[0].4s}, [$lastBlk]
|
||||
+99:
|
||||
+ ret
|
||||
+.size ${prefix}_xts_do_cipher${standard},.-${prefix}_xts_do_cipher${standard}
|
||||
+___
|
||||
+} #end of gen_xts_do_cipher
|
||||
+
|
||||
+}}}
|
||||
+
|
||||
+{{{
|
||||
+my ($enc)=("w6");
|
||||
+
|
||||
+sub gen_xts_cipher() {
|
||||
+ my $en = shift;
|
||||
+$code.=<<___;
|
||||
+.globl ${prefix}_xts_${en}crypt${standard}
|
||||
+.type ${prefix}_xts_${en}crypt${standard},%function
|
||||
+.align 5
|
||||
+${prefix}_xts_${en}crypt${standard}:
|
||||
+ stp x15, x16, [sp, #-0x10]!
|
||||
+ stp x17, x18, [sp, #-0x10]!
|
||||
+ stp x19, x20, [sp, #-0x10]!
|
||||
+ stp x21, x22, [sp, #-0x10]!
|
||||
+ stp x23, x24, [sp, #-0x10]!
|
||||
+ stp x25, x26, [sp, #-0x10]!
|
||||
+ stp x27, x28, [sp, #-0x10]!
|
||||
+ stp x29, x30, [sp, #-0x10]!
|
||||
+ stp d8, d9, [sp, #-0x10]!
|
||||
+ stp d10, d11, [sp, #-0x10]!
|
||||
+ stp d12, d13, [sp, #-0x10]!
|
||||
+ stp d14, d15, [sp, #-0x10]!
|
||||
+___
|
||||
+ &mov_en_to_enc($en,$enc);
|
||||
+$code.=<<___;
|
||||
+ bl ${prefix}_xts_do_cipher${standard}
|
||||
+ ldp d14, d15, [sp], #0x10
|
||||
+ ldp d12, d13, [sp], #0x10
|
||||
+ ldp d10, d11, [sp], #0x10
|
||||
+ ldp d8, d9, [sp], #0x10
|
||||
+ ldp x29, x30, [sp], #0x10
|
||||
+ ldp x27, x28, [sp], #0x10
|
||||
+ ldp x25, x26, [sp], #0x10
|
||||
+ ldp x23, x24, [sp], #0x10
|
||||
+ ldp x21, x22, [sp], #0x10
|
||||
+ ldp x19, x20, [sp], #0x10
|
||||
+ ldp x17, x18, [sp], #0x10
|
||||
+ ldp x15, x16, [sp], #0x10
|
||||
+ ret
|
||||
+.size ${prefix}_xts_${en}crypt${standard},.-${prefix}_xts_${en}crypt${standard}
|
||||
+___
|
||||
+
|
||||
+} # end of gen_xts_cipher
|
||||
+$standard="_gb";
|
||||
+&gen_xts_do_cipher();
|
||||
+&gen_xts_cipher("en");
|
||||
+&gen_xts_cipher("de");
|
||||
+$standard="";
|
||||
+&gen_xts_do_cipher();
|
||||
+&gen_xts_cipher("en");
|
||||
+&gen_xts_cipher("de");
|
||||
+}}}
|
||||
########################################
|
||||
{ my %opcode = (
|
||||
"sm4e" => 0xcec08400,
|
||||
diff --git a/include/crypto/sm4_platform.h b/include/crypto/sm4_platform.h
|
||||
index 2f5a6cf..0bde96f 100644
|
||||
--- a/include/crypto/sm4_platform.h
|
||||
+++ b/include/crypto/sm4_platform.h
|
||||
@@ -26,6 +26,10 @@
|
||||
# define HWSM4_cbc_encrypt sm4_v8_cbc_encrypt
|
||||
# define HWSM4_ecb_encrypt sm4_v8_ecb_encrypt
|
||||
# define HWSM4_ctr32_encrypt_blocks sm4_v8_ctr32_encrypt_blocks
|
||||
+# define HWSM4_xts_encrypt_gb sm4_v8_xts_encrypt_gb
|
||||
+# define HWSM4_xts_decrypt_gb sm4_v8_xts_decrypt_gb
|
||||
+# define HWSM4_xts_encrypt sm4_v8_xts_encrypt
|
||||
+# define HWSM4_xts_decrypt sm4_v8_xts_decrypt
|
||||
# endif
|
||||
# endif
|
||||
# endif /* OPENSSL_CPUID_OBJ */
|
||||
@@ -46,6 +50,16 @@ void HWSM4_ecb_encrypt(const unsigned char *in, unsigned char *out,
|
||||
void HWSM4_ctr32_encrypt_blocks(const unsigned char *in, unsigned char *out,
|
||||
size_t len, const void *key,
|
||||
const unsigned char ivec[16]);
|
||||
+/* xts mode in GB/T 17964-2021 */
|
||||
+void HWSM4_xts_encrypt_gb(const unsigned char *in, unsigned char *out, size_t length, const SM4_KEY *key1,
|
||||
+ const SM4_KEY *key2, const uint8_t iv[16]);
|
||||
+void HWSM4_xts_decrypt_gb(const unsigned char *in, unsigned char *out, size_t length, const SM4_KEY *key1,
|
||||
+ const SM4_KEY *key2, const uint8_t iv[16]);
|
||||
+/* xts mode in IEEE Std 1619-2007 */
|
||||
+void HWSM4_xts_encrypt(const unsigned char *in, unsigned char *out, size_t length, const SM4_KEY *key1,
|
||||
+ const SM4_KEY *key2, const uint8_t iv[16]);
|
||||
+void HWSM4_xts_decrypt(const unsigned char *in, unsigned char *out, size_t length, const SM4_KEY *key1,
|
||||
+ const SM4_KEY *key2, const uint8_t iv[16]);
|
||||
# endif /* HWSM4_CAPABLE */
|
||||
|
||||
#ifdef VPSM4_EX_CAPABLE
|
||||
--
|
||||
2.36.1
|
||||
|
6353
dependency/openssl/Feature-Support-TLCP-protocol.patch
Normal file
6353
dependency/openssl/Feature-Support-TLCP-protocol.patch
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,87 @@
|
||||
From d3e1106ea296a2ec94d27dd34692c34ad543ad04 Mon Sep 17 00:00:00 2001
|
||||
From: s_c_c <shichuchao@huawei.com>
|
||||
Date: Wed, 29 Jun 2022 17:54:50 +0800
|
||||
Subject: [PATCH] X509 command supports SM2 certificate signing with default
|
||||
sm2id
|
||||
|
||||
---
|
||||
apps/x509.c | 4 ++++
|
||||
include/openssl/sm2.h | 9 +++++++++
|
||||
test/recipes/25-test_req.t | 13 ++++++++++---
|
||||
3 files changed, 23 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/apps/x509.c b/apps/x509.c
|
||||
index 1043eba..2669894 100644
|
||||
--- a/apps/x509.c
|
||||
+++ b/apps/x509.c
|
||||
@@ -1078,6 +1078,10 @@ static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext,
|
||||
if (!X509V3_EXT_add_nconf(conf, &ctx, section, x))
|
||||
goto err;
|
||||
}
|
||||
+#ifndef OPENSSL_NO_SM2
|
||||
+ if (EVP_PKEY_is_sm2(pkey) && !EVP_PKEY_set_alias_type(pkey, EVP_PKEY_SM2))
|
||||
+ goto err;
|
||||
+#endif
|
||||
if (!X509_sign(x, pkey, digest))
|
||||
goto err;
|
||||
return 1;
|
||||
diff --git a/include/openssl/sm2.h b/include/openssl/sm2.h
|
||||
index 505ebfc..cc517bc 100644
|
||||
--- a/include/openssl/sm2.h
|
||||
+++ b/include/openssl/sm2.h
|
||||
@@ -1,3 +1,12 @@
|
||||
+/*
|
||||
+ * Copyright 2022 Huawei Technologies Co., Ltd. All Rights Reserved.
|
||||
+ *
|
||||
+ * Licensed under the OpenSSL license (the "License"). You may not use
|
||||
+ * this file except in compliance with the License. You can obtain a copy
|
||||
+ * in the file LICENSE in the source distribution or at
|
||||
+ * https://www.openssl.org/source/license.html
|
||||
+ */
|
||||
+
|
||||
#ifndef HEADER_SM2_H
|
||||
# define HEADER_SM2_H
|
||||
|
||||
diff --git a/test/recipes/25-test_req.t b/test/recipes/25-test_req.t
|
||||
index d53e577..2b0c08c 100644
|
||||
--- a/test/recipes/25-test_req.t
|
||||
+++ b/test/recipes/25-test_req.t
|
||||
@@ -182,10 +182,10 @@ subtest "generating certificate requests" => sub {
|
||||
};
|
||||
|
||||
subtest "generating SM2 certificate requests" => sub {
|
||||
- plan tests => 4;
|
||||
+ plan tests => 5;
|
||||
|
||||
SKIP: {
|
||||
- skip "SM2 is not supported by this OpenSSL build", 4
|
||||
+ skip "SM2 is not supported by this OpenSSL build", 5
|
||||
if disabled("sm2");
|
||||
ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
|
||||
"-new", "-key", srctop_file("test", "certs", "sm2.key"),
|
||||
@@ -198,6 +198,13 @@ subtest "generating SM2 certificate requests" => sub {
|
||||
"-sm2-id", "1234567812345678", "-sm3"])),
|
||||
"Verifying signature on SM2 certificate request");
|
||||
|
||||
+ # Use default sm2 id
|
||||
+ ok(run(app(["openssl", "x509", "-req", "-extfile", srctop_file("test", "CAss.cnf"),
|
||||
+ "-extensions", "v3_ca", "-sm3", "-days", "365",
|
||||
+ "-in", "testreq.pem", "-signkey", srctop_file("test", "certs", "sm2.key"),
|
||||
+ "-out", "testsign.pem"])),
|
||||
+ "Signing SM2 certificate request");
|
||||
+
|
||||
ok(run(app(["openssl", "req", "-config", srctop_file("test", "test.cnf"),
|
||||
"-new", "-key", srctop_file("test", "certs", "sm2.key"),
|
||||
"-sigopt", "sm2_hex_id:DEADBEEF",
|
||||
@@ -218,7 +225,7 @@ run_conversion('req conversions',
|
||||
run_conversion('req conversions -- testreq2',
|
||||
srctop_file("test", "testreq2.pem"));
|
||||
|
||||
-unlink "testkey.pem", "testreq.pem", "testreq_withattrs_pem.pem", "testreq_withattrs_der.pem";
|
||||
+unlink "testkey.pem", "testreq.pem", "testreq_withattrs_pem.pem", "testreq_withattrs_der.pem", "testsign.pem";
|
||||
|
||||
sub run_conversion {
|
||||
my $title = shift;
|
||||
--
|
||||
2.20.1 (Apple Git-117)
|
||||
|
File diff suppressed because it is too large
Load Diff
30
dependency/openssl/Fix-FIPS-getenv-build-failure.patch
Normal file
30
dependency/openssl/Fix-FIPS-getenv-build-failure.patch
Normal file
@ -0,0 +1,30 @@
|
||||
diff --git a/crypto/o_init.c b/crypto/o_init.c
|
||||
index b1eef43..4fbb0e5 100644
|
||||
--- a/crypto/o_init.c
|
||||
+++ b/crypto/o_init.c
|
||||
@@ -7,7 +7,7 @@
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
-/* for secure_getenv */
|
||||
+/* for ossl_safe_getenv */
|
||||
#define _GNU_SOURCE
|
||||
#include "e_os.h"
|
||||
#include <openssl/err.h>
|
||||
@@ -21,6 +21,7 @@
|
||||
# include <openssl/rand.h>
|
||||
# include <openssl/fips.h>
|
||||
# include "crypto/fips.h"
|
||||
+# include "internal/cryptlib.h"
|
||||
|
||||
# define FIPS_MODE_SWITCH_FILE "/proc/sys/crypto/fips_enabled"
|
||||
|
||||
@@ -29,7 +30,7 @@ static void init_fips_mode(void)
|
||||
char buf[2] = "0";
|
||||
int fd;
|
||||
|
||||
- if (secure_getenv("OPENSSL_FORCE_FIPS_MODE") != NULL) {
|
||||
+ if (ossl_safe_getenv("OPENSSL_FORCE_FIPS_MODE") != NULL) {
|
||||
buf[0] = '1';
|
||||
} else if ((fd = open(FIPS_MODE_SWITCH_FILE, O_RDONLY)) >= 0) {
|
||||
while (read(fd, buf, sizeof(buf)) < 0 && errno == EINTR) ;
|
182
dependency/openssl/Fix-SM4-XTS-build-failure-using-clang.patch
Normal file
182
dependency/openssl/Fix-SM4-XTS-build-failure-using-clang.patch
Normal file
@ -0,0 +1,182 @@
|
||||
From 80835d048cb2a241605beb49d17bf129ab2f5ae5 Mon Sep 17 00:00:00 2001
|
||||
From: Xu Yizhou <xuyizhou1@huawei.com>
|
||||
Date: Mon, 15 May 2023 11:41:59 +0800
|
||||
Subject: [PATCH] Fix SM4-XTS build failure using clang
|
||||
|
||||
The OpenSSL community also has similar issues, and the corresponding
|
||||
solutions can be found in this [PR]
|
||||
(https://github.com/openssl/openssl/pull/20202). Moreover, the
|
||||
community has added restrictions in the arm-xlate.pl file to recognize
|
||||
the 'LDR REG, =VALUE' pseudo instruction on Neon, as shown in this [PR]
|
||||
(https://github.com/openssl/openssl/pull/20222).
|
||||
|
||||
Signed-off-by: Xu Yizhou <xuyizhou1@huawei.com>
|
||||
---
|
||||
crypto/perlasm/arm-xlate.pl | 10 ++++++++++
|
||||
crypto/sm4/asm/sm4-armv8.pl | 12 ++++++-----
|
||||
crypto/sm4/asm/vpsm4_ex-armv8.pl | 34 ++++++++++++++++++++------------
|
||||
3 files changed, 38 insertions(+), 18 deletions(-)
|
||||
|
||||
diff --git a/crypto/perlasm/arm-xlate.pl b/crypto/perlasm/arm-xlate.pl
|
||||
index 48819be..a2f3838 100755
|
||||
--- a/crypto/perlasm/arm-xlate.pl
|
||||
+++ b/crypto/perlasm/arm-xlate.pl
|
||||
@@ -170,6 +170,16 @@ while(my $line=<>) {
|
||||
}
|
||||
}
|
||||
|
||||
+ # ldr REG, #VALUE psuedo-instruction - avoid clang issue with Neon registers
|
||||
+ #
|
||||
+ if ($line =~ /^\s*ldr\s+([qd]\d\d?)\s*,\s*=(\w+)/i) {
|
||||
+ # Immediate load via literal pool into qN or DN - clang max is 2^32-1
|
||||
+ my ($reg, $value) = ($1, $2);
|
||||
+ # If $value is hex, 0x + 8 hex chars = 10 chars total will be okay
|
||||
+ # If $value is decimal, 2^32 - 1 = 4294967295 will be okay (also 10 chars)
|
||||
+ die("$line: immediate load via literal pool into $reg: value too large for clang - redo manually") if length($value) > 10;
|
||||
+ }
|
||||
+
|
||||
print $line if ($line);
|
||||
print "\n";
|
||||
}
|
||||
diff --git a/crypto/sm4/asm/sm4-armv8.pl b/crypto/sm4/asm/sm4-armv8.pl
|
||||
index 923c1c0..07ba53a 100644
|
||||
--- a/crypto/sm4/asm/sm4-armv8.pl
|
||||
+++ b/crypto/sm4/asm/sm4-armv8.pl
|
||||
@@ -244,6 +244,8 @@ $code.=<<___;
|
||||
.long 0x10171E25, 0x2C333A41, 0x484F565D, 0x646B7279
|
||||
.Lfk:
|
||||
.long 0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc
|
||||
+.Lxts_magic:
|
||||
+ .dword 0x0101010101010187,0x0101010101010101
|
||||
___
|
||||
}}}
|
||||
|
||||
@@ -604,7 +606,7 @@ $code.=<<___;
|
||||
.globl ${prefix}_ctr32_encrypt_blocks
|
||||
.type ${prefix}_ctr32_encrypt_blocks,%function
|
||||
.align 5
|
||||
-${prefix}_ctr32_encrypt_blocks:
|
||||
+${prefix}_ctr32_encrypt_blocks:
|
||||
stp d8,d9,[sp, #-16]!
|
||||
|
||||
ld1 {$ivec.4s},[$ivp]
|
||||
@@ -736,7 +738,7 @@ $code.=<<___;
|
||||
.align 5
|
||||
${prefix}_xts_do_cipher${standard}:
|
||||
mov w$magic,0x87
|
||||
- ldr $qMagic, =0x01010101010101010101010101010187
|
||||
+ ldr $qMagic, .Lxts_magic
|
||||
// used to encrypt the XORed plaintext blocks
|
||||
ld1 {@rks[0].4s,@rks[1].4s,@rks[2].4s,@rks[3].4s},[$rk2],#64
|
||||
ld1 {@rks[4].4s,@rks[5].4s,@rks[6].4s,@rks[7].4s},[$rk2]
|
||||
@@ -963,7 +965,7 @@ $code.=<<___;
|
||||
cmp $remain,0
|
||||
b.eq 99f
|
||||
|
||||
-// This brance calculates the last two tweaks,
|
||||
+// This brance calculates the last two tweaks,
|
||||
// while the encryption/decryption length is larger than 32
|
||||
.last_2blks_tweak${standard}:
|
||||
___
|
||||
@@ -974,7 +976,7 @@ $code.=<<___;
|
||||
b .check_dec${standard}
|
||||
|
||||
|
||||
-// This brance calculates the last two tweaks,
|
||||
+// This brance calculates the last two tweaks,
|
||||
// while the encryption/decryption length is less than 32, who only need two tweaks
|
||||
.only_2blks_tweak${standard}:
|
||||
mov @tweak[1].16b,@tweak[0].16b
|
||||
@@ -1018,7 +1020,7 @@ $code.=<<___;
|
||||
strb w$tmp1,[$lastBlk,$remain]
|
||||
strb w$tmp0,[$out,$remain]
|
||||
b.gt .loop${standard}
|
||||
- ld1 {@dat[0].4s}, [$lastBlk]
|
||||
+ ld1 {@dat[0].4s}, [$lastBlk]
|
||||
eor @dat[0].16b, @dat[0].16b, @tweak[2].16b
|
||||
___
|
||||
&rev32(@dat[0],@dat[0]);
|
||||
diff --git a/crypto/sm4/asm/vpsm4_ex-armv8.pl b/crypto/sm4/asm/vpsm4_ex-armv8.pl
|
||||
index 86a6f89..4fd2975 100644
|
||||
--- a/crypto/sm4/asm/vpsm4_ex-armv8.pl
|
||||
+++ b/crypto/sm4/asm/vpsm4_ex-armv8.pl
|
||||
@@ -108,12 +108,12 @@ ___
|
||||
|
||||
sub load_sbox_matrix () {
|
||||
$code.=<<___;
|
||||
- ldr $MaskQ, =0x0306090c0f0205080b0e0104070a0d00
|
||||
- ldr $TAHMatQ, =0x22581a6002783a4062185a2042387a00
|
||||
- ldr $TALMatQ, =0xc10bb67c4a803df715df62a89e54e923
|
||||
- ldr $ATAHMatQ, =0x1407c6d56c7fbeadb9aa6b78c1d21300
|
||||
- ldr $ATALMatQ, =0xe383c1a1fe9edcbc6404462679195b3b
|
||||
- ldr $ANDMaskQ, =0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f
|
||||
+ ldr $MaskQ, .Lsbox_magic
|
||||
+ ldr $TAHMatQ, .Lsbox_magic+16
|
||||
+ ldr $TALMatQ, .Lsbox_magic+32
|
||||
+ ldr $ATAHMatQ, .Lsbox_magic+48
|
||||
+ ldr $ATALMatQ, .Lsbox_magic+64
|
||||
+ ldr $ANDMaskQ, .Lsbox_magic+80
|
||||
___
|
||||
}
|
||||
# matrix multiplication Mat*x = (lowerMat*x) ^ (higherMat*x)
|
||||
@@ -505,7 +505,7 @@ sub compute_tweak_vec() {
|
||||
my $des = shift;
|
||||
&rbit(@vtmp[2],$src);
|
||||
$code.=<<___;
|
||||
- ldr @qtmp[0], =0x01010101010101010101010101010187
|
||||
+ ldr @qtmp[0], .Lxts_magic
|
||||
shl $des.16b, @vtmp[2].16b, #1
|
||||
ext @vtmp[1].16b, @vtmp[2].16b, @vtmp[2].16b,#15
|
||||
ushr @vtmp[1].16b, @vtmp[1].16b, #7
|
||||
@@ -569,10 +569,18 @@ ${prefix}_consts:
|
||||
.long 0xA0A7AEB5, 0xBCC3CAD1, 0xD8DFE6ED, 0xF4FB0209
|
||||
.long 0x10171E25, 0x2C333A41, 0x484F565D, 0x646B7279
|
||||
.Lfk:
|
||||
- .long 0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc
|
||||
+ .long 0xa3b1bac6, 0x56aa3350, 0x677d9197, 0xb27022dc
|
||||
.Lshuffles:
|
||||
- .long 0x07060504, 0x0B0A0908, 0x0F0E0D0C, 0x03020100
|
||||
-
|
||||
+ .long 0x07060504, 0x0B0A0908, 0x0F0E0D0C, 0x03020100
|
||||
+.Lxts_magic:
|
||||
+ .dword 0x0101010101010187,0x0101010101010101
|
||||
+.Lsbox_magic:
|
||||
+ .dword 0x0b0e0104070a0d00,0x0306090c0f020508
|
||||
+ .dword 0x62185a2042387a00,0x22581a6002783a40
|
||||
+ .dword 0x15df62a89e54e923,0xc10bb67c4a803df7
|
||||
+ .dword 0xb9aa6b78c1d21300,0x1407c6d56c7fbead
|
||||
+ .dword 0x6404462679195b3b,0xe383c1a1fe9edcbc
|
||||
+ .dword 0x0f0f0f0f0f0f0f0f,0x0f0f0f0f0f0f0f0f
|
||||
.size ${prefix}_consts,.-${prefix}_consts
|
||||
___
|
||||
|
||||
@@ -1033,7 +1041,7 @@ $code.=<<___;
|
||||
cmp $remain,0
|
||||
b.eq .return${standard}
|
||||
|
||||
-// This brance calculates the last two tweaks,
|
||||
+// This brance calculates the last two tweaks,
|
||||
// while the encryption/decryption length is larger than 32
|
||||
.last_2blks_tweak${standard}:
|
||||
___
|
||||
@@ -1044,7 +1052,7 @@ $code.=<<___;
|
||||
b .check_dec${standard}
|
||||
|
||||
|
||||
-// This brance calculates the last two tweaks,
|
||||
+// This brance calculates the last two tweaks,
|
||||
// while the encryption/decryption length is equal to 32, who only need two tweaks
|
||||
.only_2blks_tweak${standard}:
|
||||
mov @tweak[1].16b,@tweak[0].16b
|
||||
@@ -1087,7 +1095,7 @@ $code.=<<___;
|
||||
strb $wtmp1,[$lastBlk,$remain]
|
||||
strb $wtmp0,[$outp,$remain]
|
||||
b.gt .loop${standard}
|
||||
- ld1 {@data[0].4s}, [$lastBlk]
|
||||
+ ld1 {@data[0].4s}, [$lastBlk]
|
||||
eor @data[0].16b, @data[0].16b, @tweak[2].16b
|
||||
___
|
||||
&rev32(@data[0],@data[0]);
|
||||
--
|
||||
2.36.1
|
||||
|
@ -0,0 +1,146 @@
|
||||
From a8f6d73fda64d514171e99a50d1483c0c0b8d968 Mon Sep 17 00:00:00 2001
|
||||
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
|
||||
Date: Sun, 12 Jun 2022 09:37:26 +0200
|
||||
Subject: [PATCH] Fix reported performance degradation on aarch64
|
||||
|
||||
This restores the implementation prior to
|
||||
commit 2621751 ("aes/asm/aesv8-armx.pl: avoid 32-bit lane assignment in CTR mode")
|
||||
for 64bit targets only, since it is reportedly 2-17% slower,
|
||||
and the silicon errata only affects 32bit targets.
|
||||
Only for 32bit targets the new algorithm is used.
|
||||
|
||||
Fixes #18445
|
||||
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
Reviewed-by: Hugo Landau <hlandau@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/18539)
|
||||
---
|
||||
crypto/aes/asm/aesv8-armx.pl | 62 ++++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 62 insertions(+)
|
||||
|
||||
diff --git a/crypto/aes/asm/aesv8-armx.pl b/crypto/aes/asm/aesv8-armx.pl
|
||||
index 2b0e982..1856d99 100755
|
||||
--- a/crypto/aes/asm/aesv8-armx.pl
|
||||
+++ b/crypto/aes/asm/aesv8-armx.pl
|
||||
@@ -740,6 +740,21 @@ $code.=<<___;
|
||||
#ifndef __ARMEB__
|
||||
rev $ctr, $ctr
|
||||
#endif
|
||||
+___
|
||||
+$code.=<<___ if ($flavour =~ /64/);
|
||||
+ vorr $dat1,$dat0,$dat0
|
||||
+ add $tctr1, $ctr, #1
|
||||
+ vorr $dat2,$dat0,$dat0
|
||||
+ add $ctr, $ctr, #2
|
||||
+ vorr $ivec,$dat0,$dat0
|
||||
+ rev $tctr1, $tctr1
|
||||
+ vmov.32 ${dat1}[3],$tctr1
|
||||
+ b.ls .Lctr32_tail
|
||||
+ rev $tctr2, $ctr
|
||||
+ sub $len,$len,#3 // bias
|
||||
+ vmov.32 ${dat2}[3],$tctr2
|
||||
+___
|
||||
+$code.=<<___ if ($flavour !~ /64/);
|
||||
add $tctr1, $ctr, #1
|
||||
vorr $ivec,$dat0,$dat0
|
||||
rev $tctr1, $tctr1
|
||||
@@ -751,6 +766,8 @@ $code.=<<___;
|
||||
vmov.32 ${ivec}[3],$tctr2
|
||||
sub $len,$len,#3 // bias
|
||||
vorr $dat2,$ivec,$ivec
|
||||
+___
|
||||
+$code.=<<___;
|
||||
b .Loop3x_ctr32
|
||||
|
||||
.align 4
|
||||
@@ -777,11 +794,25 @@ $code.=<<___;
|
||||
aese $dat1,q8
|
||||
aesmc $tmp1,$dat1
|
||||
vld1.8 {$in0},[$inp],#16
|
||||
+___
|
||||
+$code.=<<___ if ($flavour =~ /64/);
|
||||
+ vorr $dat0,$ivec,$ivec
|
||||
+___
|
||||
+$code.=<<___ if ($flavour !~ /64/);
|
||||
add $tctr0,$ctr,#1
|
||||
+___
|
||||
+$code.=<<___;
|
||||
aese $dat2,q8
|
||||
aesmc $dat2,$dat2
|
||||
vld1.8 {$in1},[$inp],#16
|
||||
+___
|
||||
+$code.=<<___ if ($flavour =~ /64/);
|
||||
+ vorr $dat1,$ivec,$ivec
|
||||
+___
|
||||
+$code.=<<___ if ($flavour !~ /64/);
|
||||
rev $tctr0,$tctr0
|
||||
+___
|
||||
+$code.=<<___;
|
||||
aese $tmp0,q9
|
||||
aesmc $tmp0,$tmp0
|
||||
aese $tmp1,q9
|
||||
@@ -790,6 +821,12 @@ $code.=<<___;
|
||||
mov $key_,$key
|
||||
aese $dat2,q9
|
||||
aesmc $tmp2,$dat2
|
||||
+___
|
||||
+$code.=<<___ if ($flavour =~ /64/);
|
||||
+ vorr $dat2,$ivec,$ivec
|
||||
+ add $tctr0,$ctr,#1
|
||||
+___
|
||||
+$code.=<<___;
|
||||
aese $tmp0,q12
|
||||
aesmc $tmp0,$tmp0
|
||||
aese $tmp1,q12
|
||||
@@ -805,22 +842,47 @@ $code.=<<___;
|
||||
aese $tmp1,q13
|
||||
aesmc $tmp1,$tmp1
|
||||
veor $in2,$in2,$rndlast
|
||||
+___
|
||||
+$code.=<<___ if ($flavour =~ /64/);
|
||||
+ rev $tctr0,$tctr0
|
||||
+ aese $tmp2,q13
|
||||
+ aesmc $tmp2,$tmp2
|
||||
+ vmov.32 ${dat0}[3], $tctr0
|
||||
+___
|
||||
+$code.=<<___ if ($flavour !~ /64/);
|
||||
vmov.32 ${ivec}[3], $tctr0
|
||||
aese $tmp2,q13
|
||||
aesmc $tmp2,$tmp2
|
||||
vorr $dat0,$ivec,$ivec
|
||||
+___
|
||||
+$code.=<<___;
|
||||
rev $tctr1,$tctr1
|
||||
aese $tmp0,q14
|
||||
aesmc $tmp0,$tmp0
|
||||
+___
|
||||
+$code.=<<___ if ($flavour !~ /64/);
|
||||
vmov.32 ${ivec}[3], $tctr1
|
||||
rev $tctr2,$ctr
|
||||
+___
|
||||
+$code.=<<___;
|
||||
aese $tmp1,q14
|
||||
aesmc $tmp1,$tmp1
|
||||
+___
|
||||
+$code.=<<___ if ($flavour =~ /64/);
|
||||
+ vmov.32 ${dat1}[3], $tctr1
|
||||
+ rev $tctr2,$ctr
|
||||
+ aese $tmp2,q14
|
||||
+ aesmc $tmp2,$tmp2
|
||||
+ vmov.32 ${dat2}[3], $tctr2
|
||||
+___
|
||||
+$code.=<<___ if ($flavour !~ /64/);
|
||||
vorr $dat1,$ivec,$ivec
|
||||
vmov.32 ${ivec}[3], $tctr2
|
||||
aese $tmp2,q14
|
||||
aesmc $tmp2,$tmp2
|
||||
vorr $dat2,$ivec,$ivec
|
||||
+___
|
||||
+$code.=<<___;
|
||||
subs $len,$len,#3
|
||||
aese $tmp0,q15
|
||||
aese $tmp1,q15
|
||||
--
|
||||
1.8.3.1
|
||||
|
82
dependency/openssl/Makefile.certificate
Normal file
82
dependency/openssl/Makefile.certificate
Normal file
@ -0,0 +1,82 @@
|
||||
UTF8 := $(shell locale -c LC_CTYPE -k | grep -q charmap.*UTF-8 && echo -utf8)
|
||||
DAYS=365
|
||||
KEYLEN=2048
|
||||
TYPE=rsa:$(KEYLEN)
|
||||
EXTRA_FLAGS=
|
||||
ifdef SERIAL
|
||||
EXTRA_FLAGS+=-set_serial $(SERIAL)
|
||||
endif
|
||||
|
||||
.PHONY: usage
|
||||
.SUFFIXES: .key .csr .crt .pem
|
||||
.PRECIOUS: %.key %.csr %.crt %.pem
|
||||
|
||||
usage:
|
||||
@echo "This makefile allows you to create:"
|
||||
@echo " o public/private key pairs"
|
||||
@echo " o SSL certificate signing requests (CSRs)"
|
||||
@echo " o self-signed SSL test certificates"
|
||||
@echo
|
||||
@echo "To create a key pair, run \"make SOMETHING.key\"."
|
||||
@echo "To create a CSR, run \"make SOMETHING.csr\"."
|
||||
@echo "To create a test certificate, run \"make SOMETHING.crt\"."
|
||||
@echo "To create a key and a test certificate in one file, run \"make SOMETHING.pem\"."
|
||||
@echo
|
||||
@echo "To create a key for use with Apache, run \"make genkey\"."
|
||||
@echo "To create a CSR for use with Apache, run \"make certreq\"."
|
||||
@echo "To create a test certificate for use with Apache, run \"make testcert\"."
|
||||
@echo
|
||||
@echo "To create a test certificate with serial number other than random, add SERIAL=num"
|
||||
@echo "You can also specify key length with KEYLEN=n and expiration in days with DAYS=n"
|
||||
@echo "Any additional options can be passed to openssl req via EXTRA_FLAGS"
|
||||
@echo
|
||||
@echo Examples:
|
||||
@echo " make server.key"
|
||||
@echo " make server.csr"
|
||||
@echo " make server.crt"
|
||||
@echo " make stunnel.pem"
|
||||
@echo " make genkey"
|
||||
@echo " make certreq"
|
||||
@echo " make testcert"
|
||||
@echo " make server.crt SERIAL=1"
|
||||
@echo " make stunnel.pem EXTRA_FLAGS=-sha384"
|
||||
@echo " make testcert DAYS=600"
|
||||
|
||||
%.pem:
|
||||
umask 77 ; \
|
||||
PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
|
||||
PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
|
||||
/usr/bin/openssl req $(UTF8) -newkey $(TYPE) -keyout $$PEM1 -nodes -x509 -days $(DAYS) -out $$PEM2 $(EXTRA_FLAGS) ; \
|
||||
cat $$PEM1 > $@ ; \
|
||||
echo "" >> $@ ; \
|
||||
cat $$PEM2 >> $@ ; \
|
||||
$(RM) $$PEM1 $$PEM2
|
||||
|
||||
%.key:
|
||||
umask 77 ; \
|
||||
/usr/bin/openssl genrsa -aes128 $(KEYLEN) > $@
|
||||
|
||||
%.csr: %.key
|
||||
umask 77 ; \
|
||||
/usr/bin/openssl req $(UTF8) -new -key $^ -out $@
|
||||
|
||||
%.crt: %.key
|
||||
umask 77 ; \
|
||||
/usr/bin/openssl req $(UTF8) -new -key $^ -x509 -days $(DAYS) -out $@ $(EXTRA_FLAGS)
|
||||
|
||||
TLSROOT=/etc/pki/tls
|
||||
KEY=$(TLSROOT)/private/localhost.key
|
||||
CSR=$(TLSROOT)/certs/localhost.csr
|
||||
CRT=$(TLSROOT)/certs/localhost.crt
|
||||
|
||||
genkey: $(KEY)
|
||||
certreq: $(CSR)
|
||||
testcert: $(CRT)
|
||||
|
||||
$(CSR): $(KEY)
|
||||
umask 77 ; \
|
||||
/usr/bin/openssl req $(UTF8) -new -key $(KEY) -out $(CSR)
|
||||
|
||||
$(CRT): $(KEY)
|
||||
umask 77 ; \
|
||||
/usr/bin/openssl req $(UTF8) -new -key $(KEY) -x509 -days $(DAYS) -out $(CRT) $(EXTRA_FLAGS)
|
@ -1,12 +1,12 @@
|
||||
open source target name ��openssl
|
||||
source code repository : product warehouse
|
||||
compile dependency: NULL
|
||||
upgrade open source package method��
|
||||
----|pull command : python $(pwd)../../build/pull_open_source.py "path" "name" "id"
|
||||
|----path : the parent directory name
|
||||
|----name��the package name in product warehouse
|
||||
|----id��pdm version id
|
||||
the compile command : python build.py -m all -f openssl-1.1.1g.tar.gz -t "comm|llt"
|
||||
To meet the requirements of compiler security options, both comm and llt are required.
|
||||
comm is used to build lib and include files, and llt is used to build bin/openssl.
|
||||
open source target name ��openssl
|
||||
source code repository : product warehouse
|
||||
compile dependency: NULL
|
||||
upgrade open source package method��
|
||||
----|pull command : python $(pwd)../../build/pull_open_source.py "path" "name" "id"
|
||||
|----path : the parent directory name
|
||||
|----name��the package name in product warehouse
|
||||
|----id��pdm version id
|
||||
the compile command : python build.py -m all -f openssl-1.1.1g.tar.gz -t "comm|llt"
|
||||
To meet the requirements of compiler security options, both comm and llt are required.
|
||||
comm is used to build lib and include files, and llt is used to build bin/openssl.
|
||||
Patch Info: None
|
191
dependency/openssl/Update-expired-SCT-certificates.patch
Normal file
191
dependency/openssl/Update-expired-SCT-certificates.patch
Normal file
@ -0,0 +1,191 @@
|
||||
From 73db5d82489b3ec09ccc772dfcee14fef0e8e908 Mon Sep 17 00:00:00 2001
|
||||
From: Tomas Mraz <tomas@openssl.org>
|
||||
Date: Wed, 1 Jun 2022 12:47:44 +0200
|
||||
Subject: [PATCH] Update expired SCT certificates
|
||||
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
|
||||
(Merged from https://github.com/openssl/openssl/pull/18446)
|
||||
---
|
||||
test/certs/embeddedSCTs1-key.pem | 38 ++++++++++++++++++++++-----------
|
||||
test/certs/embeddedSCTs1.pem | 35 +++++++++++++++---------------
|
||||
test/certs/embeddedSCTs1.sct | 12 +++++------
|
||||
test/certs/embeddedSCTs1_issuer-key.pem | 15 +++++++++++++
|
||||
test/certs/embeddedSCTs1_issuer.pem | 30 +++++++++++++-------------
|
||||
5 files changed, 79 insertions(+), 51 deletions(-)
|
||||
create mode 100644 test/certs/embeddedSCTs1_issuer-key.pem
|
||||
|
||||
diff --git a/test/certs/embeddedSCTs1-key.pem b/test/certs/embeddedSCTs1-key.pem
|
||||
index e3e66d5..28dd206 100644
|
||||
--- a/test/certs/embeddedSCTs1-key.pem
|
||||
+++ b/test/certs/embeddedSCTs1-key.pem
|
||||
@@ -1,15 +1,27 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
-MIICWwIBAAKBgQC+75jnwmh3rjhfdTJaDB0ym+3xj6r015a/BH634c4VyVui+A7k
|
||||
-WL19uG+KSyUhkaeb1wDDjpwDibRc1NyaEgqyHgy0HNDnKAWkEM2cW9tdSSdyba8X
|
||||
-EPYBhzd+olsaHjnu0LiBGdwVTcaPfajjDK8VijPmyVCfSgWwFAn/Xdh+tQIDAQAB
|
||||
-AoGAK/daG0vt6Fkqy/hdrtSJSKUVRoGRmS2nnba4Qzlwzh1+x2kdbMFuaOu2a37g
|
||||
-PvmeQclheKZ3EG1+Jb4yShwLcBCV6pkRJhOKuhvqGnjngr6uBH4gMCjpZVj7GDMf
|
||||
-flYHhdJCs3Cz/TY0wKN3o1Fldil2DHR/AEOc1nImeSp5/EUCQQDjKS3W957kYtTU
|
||||
-X5BeRjvg03Ug8tJq6IFuhTFvUJ+XQ5bAc0DmxAbQVKqRS7Wje59zTknVvS+MFdeQ
|
||||
-pz4dGuV7AkEA1y0X2yarIls+0A/S1uwkvwRTIkfS+QwFJ1zVya8sApRdKAcidIzA
|
||||
-b70hkKLilU9+LrXg5iZdFp8l752qJiw9jwJAXjItN/7mfH4fExGto+or2kbVQxxt
|
||||
-9LcFNPc2UJp2ExuL37HrL8YJrUnukOF8KJaSwBWuuFsC5GwKP4maUCdfEQJAUwBR
|
||||
-83c3DEmmMRvpeH4erpA8gTyzZN3+HvDwhpvLnjMcvBQEdnDUykVqbSBnxrCjO+Fs
|
||||
-n1qtDczWFVf8Cj2GgQJAQ14Awx32Cn9sF+3M+sEVtlAf6CqiEbkYeYdSCbsplMmZ
|
||||
-1UoaxiwXY3z+B7epsRnnPR3KaceAlAxw2/zQJMFNOQ==
|
||||
+MIIEpQIBAAKCAQEAuIjpA4/iCpDA2mjywI5zG6IBX6bNcRQYDsB7Cv0VonNXtJBw
|
||||
+XxMENP4jVpvEmWpJ5iMBknGHV+XWBkngYapczIsY4LGn6aMU6ySABBVQpNOQSRfT
|
||||
+48xGGPR9mzOBG/yplmpFOVq1j+b65lskvAXKYaLFpFn3oY/pBSdcCNBP8LypVXAJ
|
||||
+b3IqEXsBL/ErgHG9bgIRP8VxBAaryCz77kLzAXkfHL2LfSGIfNONyEKB3xI94S4L
|
||||
+eouOSoWL1VkEfJs87vG4G5xoXw3KOHyiueQUUlMnu8p+Bx0xPVKPEsLje3R9k0rG
|
||||
+a5ca7dXAn9UypKKp25x4NXpnjGX5txVEYfNvqQIDAQABAoIBAE0zqhh9Z5n3+Vbm
|
||||
+tTht4CZdXqm/xQ9b0rzJNjDgtN5j1vuJuhlsgUQSVoJzZIqydvw7BPtZV8AkPagf
|
||||
+3Cm/9lb0kpHegVsziRrfCFes+zIZ+LE7sMAKxADIuIvnvkoRKHnvN8rI8lCj16/r
|
||||
+zbCD06mJSZp6sSj8ZgZr8wsU63zRGt1TeGM67uVW4agphfzuKGlXstPLsSMwknpF
|
||||
+nxFS2TYbitxa9oH76oCpEk5fywYsYgUP4TdzOzfVAgMzNSu0FobvWl0CECB+G3RQ
|
||||
+XQ5VWbYkFoj5XbE5kYz6sYHMQWL1NQpglUp+tAQ1T8Nca0CvbSpD77doRGm7UqYw
|
||||
+ziVQKokCgYEA6BtHwzyD1PHdAYtOcy7djrpnIMaiisSxEtMhctoxg8Vr2ePEvMpZ
|
||||
+S1ka8A1Pa9GzjaUk+VWKWsTf+VkmMHGtpB1sv8S7HjujlEmeQe7p8EltjstvLDmi
|
||||
+BhAA7ixvZpXXjQV4GCVdUVu0na6gFGGueZb2FHEXB8j1amVwleJj2lcCgYEAy4f3
|
||||
+2wXqJfz15+YdJPpG9BbH9d/plKJm5ID3p2ojAGo5qvVuIJMNJA4elcfHDwzCWVmn
|
||||
+MtR/WwtxYVVmy1BAnmk6HPSYc3CStvv1800vqN3fyJWtZ1P+8WBVZWZzIQdjdiaU
|
||||
+JSRevPnjQGc+SAZQQIk1yVclbz5790yuXsdIxf8CgYEApqlABC5lsvfga4Vt1UMn
|
||||
+j57FAkHe4KmPRCcZ83A88ZNGd/QWhkD9kR7wOsIz7wVqWiDkxavoZnjLIi4jP9HA
|
||||
+jwEZ3zER8wl70bRy0IEOtZzj8A6fSzAu6Q+Au4RokU6yse3lZ+EcepjQvhBvnXLu
|
||||
+ZxxAojj6AnsHzVf9WYJvlI0CgYEAoATIw/TEgRV/KNHs/BOiEWqP0Co5dVix2Nnk
|
||||
+3EVAO6VIrbbE3OuAm2ZWeaBWSujXLHSmVfpoHubCP6prZVI1W9aTkAxmh+xsDV3P
|
||||
+o3h+DiBTP1seuGx7tr7spQqFXeR3OH9gXktYCO/W0d3aQ7pjAjpehWv0zJ+ty2MI
|
||||
+fQ/lkXUCgYEAgbP+P5UmY7Fqm/mi6TprEJ/eYktji4Ne11GDKGFQCfjF5RdKhdw1
|
||||
+5+elGhZes+cpzu5Ak6zBDu4bviT+tRTWJu5lVLEzlHHv4nAU7Ks5Aj67ApH21AnP
|
||||
+RtlATdhWOt5Dkdq1WSpDfz5bvWgvyBx9D66dSmQdbKKe2dH327eQll4=
|
||||
-----END RSA PRIVATE KEY-----
|
||||
diff --git a/test/certs/embeddedSCTs1.pem b/test/certs/embeddedSCTs1.pem
|
||||
index d1e8512..d2a111f 100644
|
||||
--- a/test/certs/embeddedSCTs1.pem
|
||||
+++ b/test/certs/embeddedSCTs1.pem
|
||||
@@ -1,20 +1,21 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
-MIIDWTCCAsKgAwIBAgIBBzANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJHQjEk
|
||||
+MIIDeDCCAuGgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBVMQswCQYDVQQGEwJHQjEk
|
||||
MCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENBMQ4wDAYDVQQIEwVX
|
||||
-YWxlczEQMA4GA1UEBxMHRXJ3IFdlbjAeFw0xMjA2MDEwMDAwMDBaFw0yMjA2MDEw
|
||||
-MDAwMDBaMFIxCzAJBgNVBAYTAkdCMSEwHwYDVQQKExhDZXJ0aWZpY2F0ZSBUcmFu
|
||||
-c3BhcmVuY3kxDjAMBgNVBAgTBVdhbGVzMRAwDgYDVQQHEwdFcncgV2VuMIGfMA0G
|
||||
-CSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+75jnwmh3rjhfdTJaDB0ym+3xj6r015a/
|
||||
-BH634c4VyVui+A7kWL19uG+KSyUhkaeb1wDDjpwDibRc1NyaEgqyHgy0HNDnKAWk
|
||||
-EM2cW9tdSSdyba8XEPYBhzd+olsaHjnu0LiBGdwVTcaPfajjDK8VijPmyVCfSgWw
|
||||
-FAn/Xdh+tQIDAQABo4IBOjCCATYwHQYDVR0OBBYEFCAxVBryXAX/2GWLaEN5T16Q
|
||||
-Nve0MH0GA1UdIwR2MHSAFF+diA3Ic+ZU1PgN2OawwSS0R8NVoVmkVzBVMQswCQYD
|
||||
-VQQGEwJHQjEkMCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENBMQ4w
|
||||
-DAYDVQQIEwVXYWxlczEQMA4GA1UEBxMHRXJ3IFdlboIBADAJBgNVHRMEAjAAMIGK
|
||||
-BgorBgEEAdZ5AgQCBHwEegB4AHYA3xwuwRUAlFJHqWFoMl3cXHlZ6PfG04j8AC4L
|
||||
-vT9012QAAAE92yffkwAABAMARzBFAiBIL2dRrzXbplQ2vh/WZA89v5pBQpSVkkUw
|
||||
-KI+j5eI+BgIhAOTtwNs6xXKx4vXoq2poBlOYfc9BAn3+/6EFUZ2J7b8IMA0GCSqG
|
||||
-SIb3DQEBBQUAA4GBAIoMS+8JnUeSea+goo5on5HhxEIb4tJpoupspOghXd7dyhUE
|
||||
-oR58h8S3foDw6XkDUmjyfKIOFmgErlVvMWmB+Wo5Srer/T4lWsAERRP+dlcMZ5Wr
|
||||
-5HAxM9MD+J86+mu8/FFzGd/ZW5NCQSEfY0A1w9B4MHpoxgdaLiDInza4kQyg
|
||||
+YWxlczEQMA4GA1UEBxMHRXJ3IFdlbjAgFw0yMDAxMjUxMTUwMTNaGA8yMTIwMDEy
|
||||
+NjExNTAxM1owGTEXMBUGA1UEAwwOc2VydmVyLmV4YW1wbGUwggEiMA0GCSqGSIb3
|
||||
+DQEBAQUAA4IBDwAwggEKAoIBAQC4iOkDj+IKkMDaaPLAjnMbogFfps1xFBgOwHsK
|
||||
+/RWic1e0kHBfEwQ0/iNWm8SZaknmIwGScYdX5dYGSeBhqlzMixjgsafpoxTrJIAE
|
||||
+FVCk05BJF9PjzEYY9H2bM4Eb/KmWakU5WrWP5vrmWyS8BcphosWkWfehj+kFJ1wI
|
||||
+0E/wvKlVcAlvcioRewEv8SuAcb1uAhE/xXEEBqvILPvuQvMBeR8cvYt9IYh8043I
|
||||
+QoHfEj3hLgt6i45KhYvVWQR8mzzu8bgbnGhfDco4fKK55BRSUye7yn4HHTE9Uo8S
|
||||
+wuN7dH2TSsZrlxrt1cCf1TKkoqnbnHg1emeMZfm3FURh82+pAgMBAAGjggEMMIIB
|
||||
+CDAdBgNVHQ4EFgQUtMa8XD5ylrF9AqCdnPEhXa63H2owHwYDVR0jBBgwFoAUX52I
|
||||
+Dchz5lTU+A3Y5rDBJLRHw1UwCQYDVR0TBAIwADATBgNVHSUEDDAKBggrBgEFBQcD
|
||||
+ATCBigYKKwYBBAHWeQIEAgR8BHoAeAB2AN8cLsEVAJRSR6lhaDJd3Fx5Wej3xtOI
|
||||
+/AAuC70/dNdkAAABb15m6AAAAAQDAEcwRQIgfDPo8RArm/vcSEZ608Q1u+XQ55QB
|
||||
+u67SZEuZxLpbUM0CIQDRsgcTud4PDy8Cgg+lHeAS7UxgSKBbWAznYOuorwNewzAZ
|
||||
+BgNVHREEEjAQgg5zZXJ2ZXIuZXhhbXBsZTANBgkqhkiG9w0BAQsFAAOBgQCWFKKR
|
||||
+RNkDRzB25NK07OLkbzebhnpKtbP4i3blRx1HAvTSamf/3uuHI7kfiPJorJymJpT1
|
||||
+IuJvSVKyMu1qONWBimiBfiyGL7+le1izHEJIP5lVTbddfzSIBIvrlHHcWIOL3H+W
|
||||
+YT6yTEIzJuO07Xp61qnB1CE2TrinUWlyC46Zkw==
|
||||
-----END CERTIFICATE-----
|
||||
diff --git a/test/certs/embeddedSCTs1.sct b/test/certs/embeddedSCTs1.sct
|
||||
index 59362dc..35c9eb9 100644
|
||||
--- a/test/certs/embeddedSCTs1.sct
|
||||
+++ b/test/certs/embeddedSCTs1.sct
|
||||
@@ -2,11 +2,11 @@ Signed Certificate Timestamp:
|
||||
Version : v1 (0x0)
|
||||
Log ID : DF:1C:2E:C1:15:00:94:52:47:A9:61:68:32:5D:DC:5C:
|
||||
79:59:E8:F7:C6:D3:88:FC:00:2E:0B:BD:3F:74:D7:64
|
||||
- Timestamp : Apr 5 17:04:16.275 2013 GMT
|
||||
+ Timestamp : Jan 1 00:00:00.000 2020 GMT
|
||||
Extensions: none
|
||||
Signature : ecdsa-with-SHA256
|
||||
- 30:45:02:20:48:2F:67:51:AF:35:DB:A6:54:36:BE:1F:
|
||||
- D6:64:0F:3D:BF:9A:41:42:94:95:92:45:30:28:8F:A3:
|
||||
- E5:E2:3E:06:02:21:00:E4:ED:C0:DB:3A:C5:72:B1:E2:
|
||||
- F5:E8:AB:6A:68:06:53:98:7D:CF:41:02:7D:FE:FF:A1:
|
||||
- 05:51:9D:89:ED:BF:08
|
||||
\ No newline at end of file
|
||||
+ 30:45:02:20:7C:33:E8:F1:10:2B:9B:FB:DC:48:46:7A:
|
||||
+ D3:C4:35:BB:E5:D0:E7:94:01:BB:AE:D2:64:4B:99:C4:
|
||||
+ BA:5B:50:CD:02:21:00:D1:B2:07:13:B9:DE:0F:0F:2F:
|
||||
+ 02:82:0F:A5:1D:E0:12:ED:4C:60:48:A0:5B:58:0C:E7:
|
||||
+ 60:EB:A8:AF:03:5E:C3
|
||||
\ No newline at end of file
|
||||
diff --git a/test/certs/embeddedSCTs1_issuer-key.pem b/test/certs/embeddedSCTs1_issuer-key.pem
|
||||
new file mode 100644
|
||||
index 0000000..9326e38
|
||||
--- /dev/null
|
||||
+++ b/test/certs/embeddedSCTs1_issuer-key.pem
|
||||
@@ -0,0 +1,15 @@
|
||||
+-----BEGIN RSA PRIVATE KEY-----
|
||||
+MIICXAIBAAKBgQDVimhTYhCicRmTbneDIRgcKkATxtB7jHbrkVfT0PtLO1FuzsvR
|
||||
+yY2RxS90P6tjXVUJnNE6uvMa5UFEJFGnTHgW8iQ8+EjPKDHM5nugSlojgZ88ujfm
|
||||
+JNnDvbKZuDnd/iYx0ss6hPx7srXFL8/BT/9Ab1zURmnLsvfP34b7arnRsQIDAQAB
|
||||
+AoGAJLR6xEJp+5IXRFlLn7WTkFvO0ddtxJ7bXhiIkTctyruyfqp7LF9Jv1G2m3PK
|
||||
+QPUtBc73w/GYkfnwIwdfJbOmPHL7XyEGHZYmEXgIgEtw6LXvAv0G5JpUnNwsSBfL
|
||||
+GfSQqI5Z5ytyzlJXkMcTGA2kTgNAYc73h4EnU+pwUnDPdAECQQD2aj+4LtYk1XPq
|
||||
+r3gjgI6MoGvgYJfPmAtZhxxVbhXQKciFUCAcBiwlQdHIdLWE9j65ctmZRWidKifr
|
||||
+4O4nz+TBAkEA3djNW/rTQq5fKZy+mCF1WYnIU/3yhJaptzRqLm7AHqe7+hdrGXJw
|
||||
++mCtU8T3L/Ms8bH1yFBZhmkp1PbR8gl48QJAQo70YyWThiN5yfxXcQ96cZWrTdIJ
|
||||
+b3NcLXSHPLQdhDqlBQ1dfvRT3ERpC8IqfZ2d162kBPhwh3MpkVcSPQK0gQJAC/dY
|
||||
+xGBYKt2a9nSk9zG+0bCT5Kvq++ngh6hFHfINXNnxUsEWns3EeEzkrIMQTj7QqszN
|
||||
+lBt5aL2dawZRNrv6EQJBAOo4STF9KEwQG0HLC/ryh1FeB0OBA5yIepXze+eJVKei
|
||||
+T0cCECOQJKfWHEzYJYDJhyEFF/sYp9TXwKSDjOifrsU=
|
||||
+-----END RSA PRIVATE KEY-----
|
||||
diff --git a/test/certs/embeddedSCTs1_issuer.pem b/test/certs/embeddedSCTs1_issuer.pem
|
||||
index 1fa449d..6aa9455 100644
|
||||
--- a/test/certs/embeddedSCTs1_issuer.pem
|
||||
+++ b/test/certs/embeddedSCTs1_issuer.pem
|
||||
@@ -1,18 +1,18 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
-MIIC0DCCAjmgAwIBAgIBADANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJHQjEk
|
||||
+MIIC0jCCAjugAwIBAgIBADANBgkqhkiG9w0BAQsFADBVMQswCQYDVQQGEwJHQjEk
|
||||
MCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENBMQ4wDAYDVQQIEwVX
|
||||
-YWxlczEQMA4GA1UEBxMHRXJ3IFdlbjAeFw0xMjA2MDEwMDAwMDBaFw0yMjA2MDEw
|
||||
-MDAwMDBaMFUxCzAJBgNVBAYTAkdCMSQwIgYDVQQKExtDZXJ0aWZpY2F0ZSBUcmFu
|
||||
-c3BhcmVuY3kgQ0ExDjAMBgNVBAgTBVdhbGVzMRAwDgYDVQQHEwdFcncgV2VuMIGf
|
||||
-MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDVimhTYhCicRmTbneDIRgcKkATxtB7
|
||||
-jHbrkVfT0PtLO1FuzsvRyY2RxS90P6tjXVUJnNE6uvMa5UFEJFGnTHgW8iQ8+EjP
|
||||
-KDHM5nugSlojgZ88ujfmJNnDvbKZuDnd/iYx0ss6hPx7srXFL8/BT/9Ab1zURmnL
|
||||
-svfP34b7arnRsQIDAQABo4GvMIGsMB0GA1UdDgQWBBRfnYgNyHPmVNT4DdjmsMEk
|
||||
-tEfDVTB9BgNVHSMEdjB0gBRfnYgNyHPmVNT4DdjmsMEktEfDVaFZpFcwVTELMAkG
|
||||
-A1UEBhMCR0IxJDAiBgNVBAoTG0NlcnRpZmljYXRlIFRyYW5zcGFyZW5jeSBDQTEO
|
||||
-MAwGA1UECBMFV2FsZXMxEDAOBgNVBAcTB0VydyBXZW6CAQAwDAYDVR0TBAUwAwEB
|
||||
-/zANBgkqhkiG9w0BAQUFAAOBgQAGCMxKbWTyIF4UbASydvkrDvqUpdryOvw4BmBt
|
||||
-OZDQoeojPUApV2lGOwRmYef6HReZFSCa6i4Kd1F2QRIn18ADB8dHDmFYT9czQiRy
|
||||
-f1HWkLxHqd81TbD26yWVXeGJPE3VICskovPkQNJ0tU4b03YmnKliibduyqQQkOFP
|
||||
-OwqULg==
|
||||
+YWxlczEQMA4GA1UEBxMHRXJ3IFdlbjAgFw0yMjA2MDExMDM4MDJaGA8yMTIyMDUw
|
||||
+ODEwMzgwMlowVTELMAkGA1UEBhMCR0IxJDAiBgNVBAoTG0NlcnRpZmljYXRlIFRy
|
||||
+YW5zcGFyZW5jeSBDQTEOMAwGA1UECBMFV2FsZXMxEDAOBgNVBAcTB0VydyBXZW4w
|
||||
+gZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANWKaFNiEKJxGZNud4MhGBwqQBPG
|
||||
+0HuMduuRV9PQ+0s7UW7Oy9HJjZHFL3Q/q2NdVQmc0Tq68xrlQUQkUadMeBbyJDz4
|
||||
+SM8oMczme6BKWiOBnzy6N+Yk2cO9spm4Od3+JjHSyzqE/HuytcUvz8FP/0BvXNRG
|
||||
+acuy98/fhvtqudGxAgMBAAGjga8wgawwHQYDVR0OBBYEFF+diA3Ic+ZU1PgN2Oaw
|
||||
+wSS0R8NVMH0GA1UdIwR2MHSAFF+diA3Ic+ZU1PgN2OawwSS0R8NVoVmkVzBVMQsw
|
||||
+CQYDVQQGEwJHQjEkMCIGA1UEChMbQ2VydGlmaWNhdGUgVHJhbnNwYXJlbmN5IENB
|
||||
+MQ4wDAYDVQQIEwVXYWxlczEQMA4GA1UEBxMHRXJ3IFdlboIBADAMBgNVHRMEBTAD
|
||||
+AQH/MA0GCSqGSIb3DQEBCwUAA4GBAD0aYh9OkFYfXV7kBfhrtD0PJG2U47OV/1qq
|
||||
++uFpqB0S1WO06eJT0pzYf1ebUcxjBkajbJZm/FHT85VthZ1lFHsky87aFD8XlJCo
|
||||
+2IOhKOkvvWKPUdFLoO/ZVXqEVKkcsS1eXK1glFvb07eJZya3JVG0KdMhV2YoDg6c
|
||||
+Doud4XrO
|
||||
-----END CERTIFICATE-----
|
||||
--
|
||||
1.8.3.1
|
||||
|
@ -0,0 +1,36 @@
|
||||
From a8da305fa3dd6e34ba5aab3978281f652fd12883 Mon Sep 17 00:00:00 2001
|
||||
From: yangyangtiantianlonglong <yangtianlong1224@163.com>
|
||||
Date: Mon, 31 Jul 2023 07:04:41 -0700
|
||||
Subject: [PATCH] A null pointer dereference occurs when memory allocation
|
||||
fails
|
||||
|
||||
Fixes #21605
|
||||
|
||||
Reviewed-by: Hugo Landau <hlandau@openssl.org>
|
||||
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/21606)
|
||||
---
|
||||
ssl/ssl_sess.c | 5 ++++-
|
||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/ssl/ssl_sess.c b/ssl/ssl_sess.c
|
||||
index cda6b7cc5b..2a5d21be79 100644
|
||||
--- a/ssl/ssl_sess.c
|
||||
+++ b/ssl/ssl_sess.c
|
||||
@@ -139,8 +139,11 @@ SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int ticket)
|
||||
dest->references = 1;
|
||||
|
||||
dest->lock = CRYPTO_THREAD_lock_new();
|
||||
- if (dest->lock == NULL)
|
||||
+ if (dest->lock == NULL) {
|
||||
+ OPENSSL_free(dest);
|
||||
+ dest = NULL;
|
||||
goto err;
|
||||
+ }
|
||||
|
||||
if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, dest, &dest->ex_data))
|
||||
goto err;
|
||||
--
|
||||
2.27.0
|
||||
|
@ -0,0 +1,49 @@
|
||||
From 23a4cbeb3ad80da3830f760f624599f24236bc38 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Tue, 7 Mar 2023 17:07:57 +0000
|
||||
Subject: [PATCH] Add a Certificate Policies Test
|
||||
|
||||
Test that a valid certificate policy is accepted and that an invalid
|
||||
certificate policy is rejected. Specifically we are checking that a
|
||||
leaf certificate with an invalid policy is detected.
|
||||
|
||||
Related-to: CVE-2023-0465
|
||||
|
||||
Reviewed-by: Hugo Landau <hlandau@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/20588)
|
||||
---
|
||||
test/recipes/25-test_verify.t | 13 ++++++++++++-
|
||||
1 file changed, 12 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/test/recipes/25-test_verify.t b/test/recipes/25-test_verify.t
|
||||
index d254bd8..a8043de 100644
|
||||
--- a/test/recipes/25-test_verify.t
|
||||
+++ b/test/recipes/25-test_verify.t
|
||||
@@ -27,7 +27,7 @@ sub verify {
|
||||
run(app([@args]));
|
||||
}
|
||||
|
||||
-plan tests => 148;
|
||||
+plan tests => 150;
|
||||
|
||||
# Canonical success
|
||||
ok(verify("ee-cert", "sslserver", ["root-cert"], ["ca-cert"]),
|
||||
@@ -421,3 +421,14 @@ SKIP: {
|
||||
"31323334353637383132333435363738"),
|
||||
"SM2 hex ID test");
|
||||
}
|
||||
+
|
||||
+# Certificate Policies
|
||||
+ok(verify("ee-cert-policies", "sslserver", ["root-cert"], ["ca-pol-cert"],
|
||||
+ "-policy_check", "-policy", "1.3.6.1.4.1.16604.998855.1",
|
||||
+ "-explicit_policy"),
|
||||
+ "Certificate policy");
|
||||
+
|
||||
+ok(!verify("ee-cert-policies-bad", "sslserver", ["root-cert"], ["ca-pol-cert"],
|
||||
+ "-policy_check", "-policy", "1.3.6.1.4.1.16604.998855.1",
|
||||
+ "-explicit_policy"),
|
||||
+ "Bad certificate policy");
|
||||
--
|
||||
2.36.1
|
||||
|
@ -0,0 +1,61 @@
|
||||
From e9ddae17e302a7e6a0daf00f25efed7c70f114d4 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Fri, 7 Jul 2023 14:39:48 +0100
|
||||
Subject: [PATCH] Add a test for CVE-2023-3446
|
||||
|
||||
Confirm that the only errors DH_check() finds with DH parameters with an
|
||||
excessively long modulus is that the modulus is too large. We should not
|
||||
be performing time consuming checks using that modulus.
|
||||
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
|
||||
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/21452)
|
||||
---
|
||||
test/dhtest.c | 15 +++++++++++++--
|
||||
1 file changed, 13 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/test/dhtest.c b/test/dhtest.c
|
||||
index 9d5609b943..00b3c47101 100644
|
||||
--- a/test/dhtest.c
|
||||
+++ b/test/dhtest.c
|
||||
@@ -63,7 +63,7 @@ static int dh_test(void)
|
||||
|| !TEST_true(DH_set0_pqg(dh, p, q, g)))
|
||||
goto err1;
|
||||
|
||||
- if (!DH_check(dh, &i))
|
||||
+ if (!TEST_true(DH_check(dh, &i)))
|
||||
goto err2;
|
||||
if (!TEST_false(i & DH_CHECK_P_NOT_PRIME)
|
||||
|| !TEST_false(i & DH_CHECK_P_NOT_SAFE_PRIME)
|
||||
@@ -123,6 +123,17 @@ static int dh_test(void)
|
||||
/* check whether the public key was calculated correctly */
|
||||
TEST_uint_eq(BN_get_word(pub_key2), 3331L);
|
||||
|
||||
+ /* Modulus of size: dh check max modulus bits + 1 */
|
||||
+ if (!TEST_true(BN_set_word(p, 1))
|
||||
+ || !TEST_true(BN_lshift(p, p, OPENSSL_DH_CHECK_MAX_MODULUS_BITS)))
|
||||
+ goto err3;
|
||||
+
|
||||
+ /*
|
||||
+ * We expect no checks at all for an excessively large modulus
|
||||
+ */
|
||||
+ if (!TEST_false(DH_check(dh, &i)))
|
||||
+ goto err3;
|
||||
+
|
||||
/*
|
||||
* II) key generation
|
||||
*/
|
||||
@@ -137,7 +148,7 @@ static int dh_test(void)
|
||||
goto err3;
|
||||
|
||||
/* ... and check whether it is valid */
|
||||
- if (!DH_check(a, &i))
|
||||
+ if (!TEST_true(DH_check(a, &i)))
|
||||
goto err3;
|
||||
if (!TEST_false(i & DH_CHECK_P_NOT_PRIME)
|
||||
|| !TEST_false(i & DH_CHECK_P_NOT_SAFE_PRIME)
|
||||
--
|
||||
2.36.1
|
||||
|
@ -0,0 +1,125 @@
|
||||
From 913ac6975162dde9e6f715c7b12869ea32ab8b70 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Mon, 4 Mar 2024 13:45:23 +0000
|
||||
Subject: [PATCH] Add a test for session cache handling
|
||||
|
||||
Repeatedly create sessions to be added to the cache and ensure we never
|
||||
exceed the expected size.
|
||||
|
||||
Related to CVE-2024-2511
|
||||
|
||||
Reviewed-by: Neil Horman <nhorman@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/24044)
|
||||
|
||||
(cherry picked from commit 5f5b9e1ca1fad0215f623b8bd4955a2e8101f306)
|
||||
Signed-off-by: Liu-Ermeng <liuermeng2@huawei.com>
|
||||
---
|
||||
test/sslapitest.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++
|
||||
1 file changed, 91 insertions(+)
|
||||
|
||||
diff --git a/test/sslapitest.c b/test/sslapitest.c
|
||||
index 5ee982ab06..2992356fdf 100644
|
||||
--- a/test/sslapitest.c
|
||||
+++ b/test/sslapitest.c
|
||||
@@ -7288,6 +7288,97 @@ static int test_inherit_verify_param(void)
|
||||
return testresult;
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * Test multiple resumptions and cache size handling
|
||||
+ * Test 0: TLSv1.3 (max_early_data set)
|
||||
+ * Test 1: TLSv1.3 (SSL_OP_NO_TICKET set)
|
||||
+ * Test 2: TLSv1.3 (max_early_data and SSL_OP_NO_TICKET set)
|
||||
+ * Test 3: TLSv1.2
|
||||
+ */
|
||||
+static int test_multi_resume(int idx)
|
||||
+{
|
||||
+ SSL_CTX *sctx = NULL, *cctx = NULL;
|
||||
+ SSL *serverssl = NULL, *clientssl = NULL;
|
||||
+ SSL_SESSION *sess = NULL;
|
||||
+ int max_version = TLS1_3_VERSION;
|
||||
+ int i, testresult = 0;
|
||||
+
|
||||
+ if (idx == 3)
|
||||
+ max_version = TLS1_2_VERSION;
|
||||
+
|
||||
+ if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(),
|
||||
+ TLS_client_method(), TLS1_VERSION,
|
||||
+ max_version, &sctx, &cctx, cert,
|
||||
+ privkey)))
|
||||
+ goto end;
|
||||
+
|
||||
+ /*
|
||||
+ * TLSv1.3 only uses a session cache if either max_early_data > 0 (used for
|
||||
+ * replay protection), or if SSL_OP_NO_TICKET is in use
|
||||
+ */
|
||||
+ if (idx == 0 || idx == 2) {
|
||||
+ if (!TEST_true(SSL_CTX_set_max_early_data(sctx, 1024)))
|
||||
+ goto end;
|
||||
+ }
|
||||
+ if (idx == 1 || idx == 2)
|
||||
+ SSL_CTX_set_options(sctx, SSL_OP_NO_TICKET);
|
||||
+
|
||||
+ SSL_CTX_sess_set_cache_size(sctx, 5);
|
||||
+
|
||||
+ for (i = 0; i < 30; i++) {
|
||||
+ if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
|
||||
+ NULL, NULL))
|
||||
+ || !TEST_true(SSL_set_session(clientssl, sess)))
|
||||
+ goto end;
|
||||
+
|
||||
+ /*
|
||||
+ * Recreate a bug where dynamically changing the max_early_data value
|
||||
+ * can cause sessions in the session cache which cannot be deleted.
|
||||
+ */
|
||||
+ if ((idx == 0 || idx == 2) && (i % 3) == 2)
|
||||
+ SSL_set_max_early_data(serverssl, 0);
|
||||
+
|
||||
+ if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))
|
||||
+ goto end;
|
||||
+
|
||||
+ if (sess == NULL || (idx == 0 && (i % 3) == 2)) {
|
||||
+ if (!TEST_false(SSL_session_reused(clientssl)))
|
||||
+ goto end;
|
||||
+ } else {
|
||||
+ if (!TEST_true(SSL_session_reused(clientssl)))
|
||||
+ goto end;
|
||||
+ }
|
||||
+ SSL_SESSION_free(sess);
|
||||
+
|
||||
+ /* Do a full handshake, followed by two resumptions */
|
||||
+ if ((i % 3) == 2) {
|
||||
+ sess = NULL;
|
||||
+ } else {
|
||||
+ if (!TEST_ptr((sess = SSL_get1_session(clientssl))))
|
||||
+ goto end;
|
||||
+ }
|
||||
+
|
||||
+ SSL_shutdown(clientssl);
|
||||
+ SSL_shutdown(serverssl);
|
||||
+ SSL_free(serverssl);
|
||||
+ SSL_free(clientssl);
|
||||
+ serverssl = clientssl = NULL;
|
||||
+ }
|
||||
+
|
||||
+ /* We should never exceed the session cache size limit */
|
||||
+ if (!TEST_long_le(SSL_CTX_sess_number(sctx), 5))
|
||||
+ goto end;
|
||||
+
|
||||
+ testresult = 1;
|
||||
+ end:
|
||||
+ SSL_free(serverssl);
|
||||
+ SSL_free(clientssl);
|
||||
+ SSL_CTX_free(sctx);
|
||||
+ SSL_CTX_free(cctx);
|
||||
+ SSL_SESSION_free(sess);
|
||||
+ return testresult;
|
||||
+}
|
||||
+
|
||||
int setup_tests(void)
|
||||
{
|
||||
if (!TEST_ptr(certsdir = test_get_argument(0))
|
||||
--
|
||||
2.33.0
|
||||
|
@ -0,0 +1,176 @@
|
||||
From 1659dc936a8763a243d09c2a6484eb1f25580ef4 Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Fri, 15 Jul 2022 13:26:33 +0100
|
||||
Subject: [PATCH] Add a test for session cache overflow
|
||||
|
||||
Test sessions behave as we expect even in the case that an overflow
|
||||
occurs when adding a new session into the session cache.
|
||||
|
||||
Related to CVE-2024-2511
|
||||
|
||||
Reviewed-by: Neil Horman <nhorman@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/24044)
|
||||
|
||||
(cherry picked from commit ddead0935d77ba9b771d632ace61b145d7153f18)
|
||||
Signed-off-by: Liu-Ermeng <liuermeng2@huawei.com>
|
||||
---
|
||||
test/sslapitest.c | 130 ++++++++++++++++++++++++++++++++++++++++++++--
|
||||
1 file changed, 127 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/test/sslapitest.c b/test/sslapitest.c
|
||||
index 472b1224ca..395b1e5457 100644
|
||||
--- a/test/sslapitest.c
|
||||
+++ b/test/sslapitest.c
|
||||
@@ -6669,6 +6669,128 @@ static int test_ca_names(int tst)
|
||||
return testresult;
|
||||
}
|
||||
|
||||
+/*
|
||||
+ * Test that a session cache overflow works as expected
|
||||
+ * Test 0: TLSv1.3, timeout on new session later than old session
|
||||
+ * Test 1: TLSv1.2, timeout on new session later than old session
|
||||
+ * Test 2: TLSv1.3, timeout on new session earlier than old session
|
||||
+ * Test 3: TLSv1.2, timeout on new session earlier than old session
|
||||
+ */
|
||||
+#if !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2)
|
||||
+static int test_session_cache_overflow(int idx)
|
||||
+{
|
||||
+ SSL_CTX *sctx = NULL, *cctx = NULL;
|
||||
+ SSL *serverssl = NULL, *clientssl = NULL;
|
||||
+ int testresult = 0;
|
||||
+ SSL_SESSION *sess = NULL;
|
||||
+
|
||||
+#ifdef OPENSSL_NO_TLS1_3
|
||||
+ /* If no TLSv1.3 available then do nothing in this case */
|
||||
+ if (idx % 2 == 0)
|
||||
+ TEST_info("No TLSv1.3 available");
|
||||
+ return 1;
|
||||
+#endif
|
||||
+#ifdef OPENSSL_NO_TLS1_2
|
||||
+ /* If no TLSv1.2 available then do nothing in this case */
|
||||
+ if (idx % 2 == 1)
|
||||
+ TEST_info("No TLSv1.2 available");
|
||||
+ return 1;
|
||||
+#endif
|
||||
+
|
||||
+ if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(),
|
||||
+ TLS_client_method(), TLS1_VERSION,
|
||||
+ (idx % 2 == 0) ? TLS1_3_VERSION
|
||||
+ : TLS1_2_VERSION,
|
||||
+ &sctx, &cctx, cert, privkey))
|
||||
+ || !TEST_true(SSL_CTX_set_options(sctx, SSL_OP_NO_TICKET)))
|
||||
+ goto end;
|
||||
+
|
||||
+ SSL_CTX_sess_set_get_cb(sctx, get_session_cb);
|
||||
+ get_sess_val = NULL;
|
||||
+
|
||||
+ SSL_CTX_sess_set_cache_size(sctx, 1);
|
||||
+
|
||||
+ if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
|
||||
+ NULL, NULL)))
|
||||
+ goto end;
|
||||
+
|
||||
+ if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))
|
||||
+ goto end;
|
||||
+
|
||||
+ if (idx > 1) {
|
||||
+ sess = SSL_get_session(serverssl);
|
||||
+ if (!TEST_ptr(sess))
|
||||
+ goto end;
|
||||
+
|
||||
+ /*
|
||||
+ * Cause this session to have a longer timeout than the next session to
|
||||
+ * be added.
|
||||
+ */
|
||||
+ if (!TEST_true(SSL_SESSION_set_timeout(sess, LONG_MAX / 2))) {
|
||||
+ sess = NULL;
|
||||
+ goto end;
|
||||
+ }
|
||||
+ sess = NULL;
|
||||
+ }
|
||||
+
|
||||
+ SSL_shutdown(serverssl);
|
||||
+ SSL_shutdown(clientssl);
|
||||
+ SSL_free(serverssl);
|
||||
+ SSL_free(clientssl);
|
||||
+ serverssl = clientssl = NULL;
|
||||
+
|
||||
+ /*
|
||||
+ * Session cache size is 1 and we already populated the cache with a session
|
||||
+ * so the next connection should cause an overflow.
|
||||
+ */
|
||||
+
|
||||
+ if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
|
||||
+ NULL, NULL)))
|
||||
+ goto end;
|
||||
+
|
||||
+ if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))
|
||||
+ goto end;
|
||||
+
|
||||
+ /*
|
||||
+ * The session we just negotiated may have been already removed from the
|
||||
+ * internal cache - but we will return it anyway from our external cache.
|
||||
+ */
|
||||
+ get_sess_val = SSL_get_session(serverssl);
|
||||
+ if (!TEST_ptr(get_sess_val))
|
||||
+ goto end;
|
||||
+ sess = SSL_get1_session(clientssl);
|
||||
+ if (!TEST_ptr(sess))
|
||||
+ goto end;
|
||||
+
|
||||
+ SSL_shutdown(serverssl);
|
||||
+ SSL_shutdown(clientssl);
|
||||
+ SSL_free(serverssl);
|
||||
+ SSL_free(clientssl);
|
||||
+ serverssl = clientssl = NULL;
|
||||
+
|
||||
+ if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,
|
||||
+ NULL, NULL)))
|
||||
+ goto end;
|
||||
+
|
||||
+ if (!TEST_true(SSL_set_session(clientssl, sess)))
|
||||
+ goto end;
|
||||
+
|
||||
+ if (!TEST_true(create_ssl_connection(serverssl, clientssl, SSL_ERROR_NONE)))
|
||||
+ goto end;
|
||||
+
|
||||
+ testresult = 1;
|
||||
+
|
||||
+ end:
|
||||
+ SSL_free(serverssl);
|
||||
+ SSL_free(clientssl);
|
||||
+ SSL_CTX_free(sctx);
|
||||
+ SSL_CTX_free(cctx);
|
||||
+ SSL_SESSION_free(sess);
|
||||
+
|
||||
+ return testresult;
|
||||
+}
|
||||
+#endif /* !defined(OPENSSL_NO_TLS1_3) || !defined(OPENSSL_NO_TLS1_2) */
|
||||
+
|
||||
/*
|
||||
* Test 0: Client sets servername and server acknowledges it (TLSv1.2)
|
||||
* Test 1: Client sets servername and server does not acknowledge it (TLSv1.2)
|
||||
@@ -7357,14 +7479,16 @@ static int test_multi_resume(int idx)
|
||||
|
||||
#if defined(OPENSSL_NO_TLS1_2)
|
||||
if (idx == 4)
|
||||
- return TEST_skip("TLSv1.2 is disabled in this build");
|
||||
+ TEST_info("TLSv1.2 is disabled in this build");
|
||||
+ return 1;
|
||||
#else
|
||||
if (idx == 4)
|
||||
max_version = TLS1_2_VERSION;
|
||||
#endif
|
||||
-#if defined(OSSL_NO_USABLE_TLS1_3)
|
||||
+#if defined(OPENSSL_NO_TLS1_3)
|
||||
if (idx != 4)
|
||||
- return TEST_skip("No usable TLSv1.3 in this build");
|
||||
+ TEST_info("No usable TLSv1.3 in this build");
|
||||
+ return 1;
|
||||
#endif
|
||||
|
||||
if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(),
|
||||
--
|
||||
2.33.0
|
||||
|
@ -0,0 +1,47 @@
|
||||
From 8ddacec11481a37302c19f4454e23299af399f83 Mon Sep 17 00:00:00 2001
|
||||
From: mlitre <martinlitre@mac.com>
|
||||
Date: Mon, 1 May 2023 11:07:21 +0200
|
||||
Subject: [PATCH] Add negative integer check when using ASN1_BIT_STRING
|
||||
|
||||
The negative integer check is done to prevent potential overflow.
|
||||
Fixes #20719.
|
||||
|
||||
CLA: trivial
|
||||
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/20862)
|
||||
|
||||
(cherry picked from commit 1258a8e4361320cd3cfaf9ede692492ce01034c8)
|
||||
|
||||
---
|
||||
crypto/asn1/a_bitstr.c | 6 ++++++
|
||||
1 file changed, 6 insertions(+)
|
||||
|
||||
diff --git a/crypto/asn1/a_bitstr.c b/crypto/asn1/a_bitstr.c
|
||||
index f462dd1073..31a1e11359 100644
|
||||
--- a/crypto/asn1/a_bitstr.c
|
||||
+++ b/crypto/asn1/a_bitstr.c
|
||||
@@ -148,6 +148,9 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
|
||||
int w, v, iv;
|
||||
unsigned char *c;
|
||||
|
||||
+ if (n < 0)
|
||||
+ return 0;
|
||||
+
|
||||
w = n / 8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
iv = ~v;
|
||||
@@ -182,6 +185,9 @@ int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n)
|
||||
{
|
||||
int w, v;
|
||||
|
||||
+ if (n < 0)
|
||||
+ return 0;
|
||||
+
|
||||
w = n / 8;
|
||||
v = 1 << (7 - (n & 0x07));
|
||||
if ((a == NULL) || (a->length < (w + 1)) || (a->data == NULL))
|
||||
--
|
||||
2.27.0
|
||||
|
@ -0,0 +1,65 @@
|
||||
From 17519e2595b5ed8211a7763ff6eb2d6cf47c13cb Mon Sep 17 00:00:00 2001
|
||||
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
|
||||
Date: Thu, 19 May 2022 15:50:28 +0200
|
||||
Subject: [PATCH] Backport a missing bug-fix from master
|
||||
|
||||
This is a backport of the following commit from master:
|
||||
|
||||
commit 61b0fead5e6079ca826594df5b9ca00e65883cb0
|
||||
Author: Matt Caswell <matt@openssl.org>
|
||||
Date: Thu Nov 19 13:58:21 2020 +0000
|
||||
|
||||
Don't Overflow when printing Thawte Strong Extranet Version
|
||||
|
||||
When printing human readable info on the Thawte Strong Extranet extension
|
||||
the version number could overflow if the version number == LONG_MAX. This
|
||||
is undefined behaviour.
|
||||
|
||||
Issue found by OSSFuzz.
|
||||
|
||||
Reviewed-by: Ben Kaduk <kaduk@mit.edu>
|
||||
(Merged from https://github.com/openssl/openssl/pull/13452)
|
||||
|
||||
Reviewed-by: Matt Caswell <matt@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/18347)
|
||||
---
|
||||
crypto/x509v3/v3_sxnet.c | 18 +++++++++++++++---
|
||||
1 files changed, 15 insertions(+), 3 deletions(-)
|
||||
create mode 100644 fuzz/corpora/crl/4d72381f46c50eb9cabd8aa27f456962bf013b28
|
||||
|
||||
diff --git a/crypto/x509v3/v3_sxnet.c b/crypto/x509v3/v3_sxnet.c
|
||||
index 89cda01be2..0648553ae3 100644
|
||||
--- a/crypto/x509v3/v3_sxnet.c
|
||||
+++ b/crypto/x509v3/v3_sxnet.c
|
||||
@@ -57,12 +57,24 @@ IMPLEMENT_ASN1_FUNCTIONS(SXNET)
|
||||
static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
|
||||
int indent)
|
||||
{
|
||||
- long v;
|
||||
+ int64_t v;
|
||||
char *tmp;
|
||||
SXNETID *id;
|
||||
int i;
|
||||
- v = ASN1_INTEGER_get(sx->version);
|
||||
- BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", v + 1, v);
|
||||
+
|
||||
+ /*
|
||||
+ * Since we add 1 to the version number to display it, we don't support
|
||||
+ * LONG_MAX since that would cause on overflow.
|
||||
+ */
|
||||
+ if (!ASN1_INTEGER_get_int64(&v, sx->version)
|
||||
+ || v >= LONG_MAX
|
||||
+ || v < LONG_MIN) {
|
||||
+ BIO_printf(out, "%*sVersion: <unsupported>", indent, "");
|
||||
+ } else {
|
||||
+ long vl = (long)v;
|
||||
+
|
||||
+ BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", vl + 1, vl);
|
||||
+ }
|
||||
for (i = 0; i < sk_SXNETID_num(sx->ids); i++) {
|
||||
id = sk_SXNETID_value(sx->ids, i);
|
||||
tmp = i2s_ASN1_INTEGER(NULL, id->zone);
|
||||
--
|
||||
2.38.1.windows.1
|
||||
|
@ -0,0 +1,464 @@
|
||||
From 3f499b24f3bcd66db022074f7e8b4f6ee266a3ae Mon Sep 17 00:00:00 2001
|
||||
From: Bernd Edlinger <bernd.edlinger@hotmail.de>
|
||||
Date: Mon, 13 Feb 2023 17:46:41 +0100
|
||||
Subject: [PATCH] Alternative fix for CVE-2022-4304
|
||||
|
||||
NOTE: This patch replaces the original patch for
|
||||
CVE-2022-4304 (43d8f88511991533f53680a751e9326999a6a31f).
|
||||
|
||||
This is about a timing leak in the topmost limb
|
||||
of the internal result of RSA_private_decrypt,
|
||||
before the padding check.
|
||||
|
||||
There are in fact at least three bugs together that
|
||||
caused the timing leak:
|
||||
|
||||
First and probably most important is the fact that
|
||||
the blinding did not use the constant time code path
|
||||
at all when the RSA object was used for a private
|
||||
decrypt, due to the fact that the Montgomery context
|
||||
rsa->_method_mod_n was not set up early enough in
|
||||
rsa_ossl_private_decrypt, when BN_BLINDING_create_param
|
||||
needed it, and that was persisted as blinding->m_ctx,
|
||||
although the RSA object creates the Montgomery context
|
||||
just a bit later.
|
||||
|
||||
Then the infamous bn_correct_top was used on the
|
||||
secret value right after the blinding was removed.
|
||||
|
||||
And finally the function BN_bn2binpad did not use
|
||||
the constant-time code path since the BN_FLG_CONSTTIME
|
||||
was not set on the secret value.
|
||||
|
||||
In order to address the first problem, this patch
|
||||
makes sure that the rsa->_method_mod_n is initialized
|
||||
right before the blinding context.
|
||||
|
||||
And to fix the second problem, we add a new utility
|
||||
function bn_correct_top_consttime, a const-time
|
||||
variant of bn_correct_top.
|
||||
|
||||
Together with the fact, that BN_bn2binpad is already
|
||||
constant time if the flag BN_FLG_CONSTTIME is set,
|
||||
this should eliminate the timing oracle completely.
|
||||
|
||||
In addition the no-asm variant may also have
|
||||
branches that depend on secret values, because the last
|
||||
invocation of bn_sub_words in bn_from_montgomery_word
|
||||
had branches when the function is compiled by certain
|
||||
gcc compiler versions, due to the clumsy coding style.
|
||||
|
||||
So additionally this patch stream-lined the no-asm
|
||||
C-code in order to avoid branches where possible and
|
||||
improve the resulting code quality.
|
||||
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
(Merged from https://github.com/openssl/openssl/pull/20284)
|
||||
|
||||
---
|
||||
CHANGES | 10 ++++
|
||||
crypto/bn/bn_asm.c | 106 +++++++++++++++++++++++-------------------
|
||||
crypto/bn/bn_blind.c | 3 +-
|
||||
crypto/bn/bn_lib.c | 22 +++++++++
|
||||
crypto/bn/bn_local.h | 26 +++++------
|
||||
crypto/rsa/rsa_ossl.c | 13 +++---
|
||||
6 files changed, 111 insertions(+), 69 deletions(-)
|
||||
|
||||
diff --git a/crypto/bn/bn_asm.c b/crypto/bn/bn_asm.c
|
||||
index 4d83a8cf11..177558c647 100644
|
||||
--- a/crypto/bn/bn_asm.c
|
||||
+++ b/crypto/bn/bn_asm.c
|
||||
@@ -381,25 +381,33 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
#ifndef OPENSSL_SMALL_FOOTPRINT
|
||||
while (n & ~3) {
|
||||
t1 = a[0];
|
||||
- t2 = b[0];
|
||||
- r[0] = (t1 - t2 - c) & BN_MASK2;
|
||||
- if (t1 != t2)
|
||||
- c = (t1 < t2);
|
||||
+ t2 = (t1 - c) & BN_MASK2;
|
||||
+ c = (t2 > t1);
|
||||
+ t1 = b[0];
|
||||
+ t1 = (t2 - t1) & BN_MASK2;
|
||||
+ r[0] = t1;
|
||||
+ c += (t1 > t2);
|
||||
t1 = a[1];
|
||||
- t2 = b[1];
|
||||
- r[1] = (t1 - t2 - c) & BN_MASK2;
|
||||
- if (t1 != t2)
|
||||
- c = (t1 < t2);
|
||||
+ t2 = (t1 - c) & BN_MASK2;
|
||||
+ c = (t2 > t1);
|
||||
+ t1 = b[1];
|
||||
+ t1 = (t2 - t1) & BN_MASK2;
|
||||
+ r[1] = t1;
|
||||
+ c += (t1 > t2);
|
||||
t1 = a[2];
|
||||
- t2 = b[2];
|
||||
- r[2] = (t1 - t2 - c) & BN_MASK2;
|
||||
- if (t1 != t2)
|
||||
- c = (t1 < t2);
|
||||
+ t2 = (t1 - c) & BN_MASK2;
|
||||
+ c = (t2 > t1);
|
||||
+ t1 = b[2];
|
||||
+ t1 = (t2 - t1) & BN_MASK2;
|
||||
+ r[2] = t1;
|
||||
+ c += (t1 > t2);
|
||||
t1 = a[3];
|
||||
- t2 = b[3];
|
||||
- r[3] = (t1 - t2 - c) & BN_MASK2;
|
||||
- if (t1 != t2)
|
||||
- c = (t1 < t2);
|
||||
+ t2 = (t1 - c) & BN_MASK2;
|
||||
+ c = (t2 > t1);
|
||||
+ t1 = b[3];
|
||||
+ t1 = (t2 - t1) & BN_MASK2;
|
||||
+ r[3] = t1;
|
||||
+ c += (t1 > t2);
|
||||
a += 4;
|
||||
b += 4;
|
||||
r += 4;
|
||||
@@ -408,10 +416,12 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
#endif
|
||||
while (n) {
|
||||
t1 = a[0];
|
||||
- t2 = b[0];
|
||||
- r[0] = (t1 - t2 - c) & BN_MASK2;
|
||||
- if (t1 != t2)
|
||||
- c = (t1 < t2);
|
||||
+ t2 = (t1 - c) & BN_MASK2;
|
||||
+ c = (t2 > t1);
|
||||
+ t1 = b[0];
|
||||
+ t1 = (t2 - t1) & BN_MASK2;
|
||||
+ r[0] = t1;
|
||||
+ c += (t1 > t2);
|
||||
a++;
|
||||
b++;
|
||||
r++;
|
||||
@@ -446,7 +456,7 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
t += c0; /* no carry */ \
|
||||
c0 = (BN_ULONG)Lw(t); \
|
||||
hi = (BN_ULONG)Hw(t); \
|
||||
- c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \
|
||||
+ c1 = (c1+hi)&BN_MASK2; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define mul_add_c2(a,b,c0,c1,c2) do { \
|
||||
@@ -455,11 +465,11 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
BN_ULLONG tt = t+c0; /* no carry */ \
|
||||
c0 = (BN_ULONG)Lw(tt); \
|
||||
hi = (BN_ULONG)Hw(tt); \
|
||||
- c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \
|
||||
+ c1 = (c1+hi)&BN_MASK2; c2 += (c1<hi); \
|
||||
t += c0; /* no carry */ \
|
||||
c0 = (BN_ULONG)Lw(t); \
|
||||
hi = (BN_ULONG)Hw(t); \
|
||||
- c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \
|
||||
+ c1 = (c1+hi)&BN_MASK2; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define sqr_add_c(a,i,c0,c1,c2) do { \
|
||||
@@ -468,7 +478,7 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
t += c0; /* no carry */ \
|
||||
c0 = (BN_ULONG)Lw(t); \
|
||||
hi = (BN_ULONG)Hw(t); \
|
||||
- c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \
|
||||
+ c1 = (c1+hi)&BN_MASK2; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define sqr_add_c2(a,i,j,c0,c1,c2) \
|
||||
@@ -483,26 +493,26 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
BN_ULONG ta = (a), tb = (b); \
|
||||
BN_ULONG lo, hi; \
|
||||
BN_UMULT_LOHI(lo,hi,ta,tb); \
|
||||
- c0 += lo; hi += (c0<lo)?1:0; \
|
||||
- c1 += hi; c2 += (c1<hi)?1:0; \
|
||||
+ c0 += lo; hi += (c0<lo); \
|
||||
+ c1 += hi; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define mul_add_c2(a,b,c0,c1,c2) do { \
|
||||
BN_ULONG ta = (a), tb = (b); \
|
||||
BN_ULONG lo, hi, tt; \
|
||||
BN_UMULT_LOHI(lo,hi,ta,tb); \
|
||||
- c0 += lo; tt = hi+((c0<lo)?1:0); \
|
||||
- c1 += tt; c2 += (c1<tt)?1:0; \
|
||||
- c0 += lo; hi += (c0<lo)?1:0; \
|
||||
- c1 += hi; c2 += (c1<hi)?1:0; \
|
||||
+ c0 += lo; tt = hi + (c0<lo); \
|
||||
+ c1 += tt; c2 += (c1<tt); \
|
||||
+ c0 += lo; hi += (c0<lo); \
|
||||
+ c1 += hi; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define sqr_add_c(a,i,c0,c1,c2) do { \
|
||||
BN_ULONG ta = (a)[i]; \
|
||||
BN_ULONG lo, hi; \
|
||||
BN_UMULT_LOHI(lo,hi,ta,ta); \
|
||||
- c0 += lo; hi += (c0<lo)?1:0; \
|
||||
- c1 += hi; c2 += (c1<hi)?1:0; \
|
||||
+ c0 += lo; hi += (c0<lo); \
|
||||
+ c1 += hi; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define sqr_add_c2(a,i,j,c0,c1,c2) \
|
||||
@@ -517,26 +527,26 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
BN_ULONG ta = (a), tb = (b); \
|
||||
BN_ULONG lo = ta * tb; \
|
||||
BN_ULONG hi = BN_UMULT_HIGH(ta,tb); \
|
||||
- c0 += lo; hi += (c0<lo)?1:0; \
|
||||
- c1 += hi; c2 += (c1<hi)?1:0; \
|
||||
+ c0 += lo; hi += (c0<lo); \
|
||||
+ c1 += hi; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define mul_add_c2(a,b,c0,c1,c2) do { \
|
||||
BN_ULONG ta = (a), tb = (b), tt; \
|
||||
BN_ULONG lo = ta * tb; \
|
||||
BN_ULONG hi = BN_UMULT_HIGH(ta,tb); \
|
||||
- c0 += lo; tt = hi + ((c0<lo)?1:0); \
|
||||
- c1 += tt; c2 += (c1<tt)?1:0; \
|
||||
- c0 += lo; hi += (c0<lo)?1:0; \
|
||||
- c1 += hi; c2 += (c1<hi)?1:0; \
|
||||
+ c0 += lo; tt = hi + (c0<lo); \
|
||||
+ c1 += tt; c2 += (c1<tt); \
|
||||
+ c0 += lo; hi += (c0<lo); \
|
||||
+ c1 += hi; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define sqr_add_c(a,i,c0,c1,c2) do { \
|
||||
BN_ULONG ta = (a)[i]; \
|
||||
BN_ULONG lo = ta * ta; \
|
||||
BN_ULONG hi = BN_UMULT_HIGH(ta,ta); \
|
||||
- c0 += lo; hi += (c0<lo)?1:0; \
|
||||
- c1 += hi; c2 += (c1<hi)?1:0; \
|
||||
+ c0 += lo; hi += (c0<lo); \
|
||||
+ c1 += hi; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define sqr_add_c2(a,i,j,c0,c1,c2) \
|
||||
@@ -551,8 +561,8 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
BN_ULONG lo = LBITS(a), hi = HBITS(a); \
|
||||
BN_ULONG bl = LBITS(b), bh = HBITS(b); \
|
||||
mul64(lo,hi,bl,bh); \
|
||||
- c0 = (c0+lo)&BN_MASK2; if (c0<lo) hi++; \
|
||||
- c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \
|
||||
+ c0 = (c0+lo)&BN_MASK2; hi += (c0<lo); \
|
||||
+ c1 = (c1+hi)&BN_MASK2; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define mul_add_c2(a,b,c0,c1,c2) do { \
|
||||
@@ -561,17 +571,17 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
BN_ULONG bl = LBITS(b), bh = HBITS(b); \
|
||||
mul64(lo,hi,bl,bh); \
|
||||
tt = hi; \
|
||||
- c0 = (c0+lo)&BN_MASK2; if (c0<lo) tt++; \
|
||||
- c1 = (c1+tt)&BN_MASK2; if (c1<tt) c2++; \
|
||||
- c0 = (c0+lo)&BN_MASK2; if (c0<lo) hi++; \
|
||||
- c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \
|
||||
+ c0 = (c0+lo)&BN_MASK2; tt += (c0<lo); \
|
||||
+ c1 = (c1+tt)&BN_MASK2; c2 += (c1<tt); \
|
||||
+ c0 = (c0+lo)&BN_MASK2; hi += (c0<lo); \
|
||||
+ c1 = (c1+hi)&BN_MASK2; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define sqr_add_c(a,i,c0,c1,c2) do { \
|
||||
BN_ULONG lo, hi; \
|
||||
sqr64(lo,hi,(a)[i]); \
|
||||
- c0 = (c0+lo)&BN_MASK2; if (c0<lo) hi++; \
|
||||
- c1 = (c1+hi)&BN_MASK2; if (c1<hi) c2++; \
|
||||
+ c0 = (c0+lo)&BN_MASK2; hi += (c0<lo); \
|
||||
+ c1 = (c1+hi)&BN_MASK2; c2 += (c1<hi); \
|
||||
} while(0)
|
||||
|
||||
# define sqr_add_c2(a,i,j,c0,c1,c2) \
|
||||
diff --git a/crypto/bn/bn_blind.c b/crypto/bn/bn_blind.c
|
||||
index 15d9e0a544..e76f6107a7 100644
|
||||
--- a/crypto/bn/bn_blind.c
|
||||
+++ b/crypto/bn/bn_blind.c
|
||||
@@ -191,7 +191,8 @@ int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b,
|
||||
n->top = (int)(rtop & ~mask) | (ntop & mask);
|
||||
n->flags |= (BN_FLG_FIXED_TOP & ~mask);
|
||||
}
|
||||
- ret = BN_mod_mul_montgomery(n, n, r, b->m_ctx, ctx);
|
||||
+ ret = bn_mul_mont_fixed_top(n, n, r, b->m_ctx, ctx);
|
||||
+ bn_correct_top_consttime(n);
|
||||
} else {
|
||||
ret = BN_mod_mul(n, n, r, b->mod, ctx);
|
||||
}
|
||||
diff --git a/crypto/bn/bn_lib.c b/crypto/bn/bn_lib.c
|
||||
index eb4a31849b..fe6fb0e40f 100644
|
||||
--- a/crypto/bn/bn_lib.c
|
||||
+++ b/crypto/bn/bn_lib.c
|
||||
@@ -1001,6 +1001,28 @@ BIGNUM *bn_wexpand(BIGNUM *a, int words)
|
||||
return (words <= a->dmax) ? a : bn_expand2(a, words);
|
||||
}
|
||||
|
||||
+void bn_correct_top_consttime(BIGNUM *a)
|
||||
+{
|
||||
+ int j, atop;
|
||||
+ BN_ULONG limb;
|
||||
+ unsigned int mask;
|
||||
+
|
||||
+ for (j = 0, atop = 0; j < a->dmax; j++) {
|
||||
+ limb = a->d[j];
|
||||
+ limb |= 0 - limb;
|
||||
+ limb >>= BN_BITS2 - 1;
|
||||
+ limb = 0 - limb;
|
||||
+ mask = (unsigned int)limb;
|
||||
+ mask &= constant_time_msb(j - a->top);
|
||||
+ atop = constant_time_select_int(mask, j + 1, atop);
|
||||
+ }
|
||||
+
|
||||
+ mask = constant_time_eq_int(atop, 0);
|
||||
+ a->top = atop;
|
||||
+ a->neg = constant_time_select_int(mask, 0, a->neg);
|
||||
+ a->flags &= ~BN_FLG_FIXED_TOP;
|
||||
+}
|
||||
+
|
||||
void bn_correct_top(BIGNUM *a)
|
||||
{
|
||||
BN_ULONG *ftl;
|
||||
diff --git a/crypto/bn/bn_local.h b/crypto/bn/bn_local.h
|
||||
index ee6342b60c..818e34348e 100644
|
||||
--- a/crypto/bn/bn_local.h
|
||||
+++ b/crypto/bn/bn_local.h
|
||||
@@ -515,10 +515,10 @@ unsigned __int64 _umul128(unsigned __int64 a, unsigned __int64 b,
|
||||
ret = (r); \
|
||||
BN_UMULT_LOHI(low,high,w,tmp); \
|
||||
ret += (c); \
|
||||
- (c) = (ret<(c))?1:0; \
|
||||
+ (c) = (ret<(c)); \
|
||||
(c) += high; \
|
||||
ret += low; \
|
||||
- (c) += (ret<low)?1:0; \
|
||||
+ (c) += (ret<low); \
|
||||
(r) = ret; \
|
||||
}
|
||||
|
||||
@@ -527,7 +527,7 @@ unsigned __int64 _umul128(unsigned __int64 a, unsigned __int64 b,
|
||||
BN_UMULT_LOHI(low,high,w,ta); \
|
||||
ret = low + (c); \
|
||||
(c) = high; \
|
||||
- (c) += (ret<low)?1:0; \
|
||||
+ (c) += (ret<low); \
|
||||
(r) = ret; \
|
||||
}
|
||||
|
||||
@@ -543,10 +543,10 @@ unsigned __int64 _umul128(unsigned __int64 a, unsigned __int64 b,
|
||||
high= BN_UMULT_HIGH(w,tmp); \
|
||||
ret += (c); \
|
||||
low = (w) * tmp; \
|
||||
- (c) = (ret<(c))?1:0; \
|
||||
+ (c) = (ret<(c)); \
|
||||
(c) += high; \
|
||||
ret += low; \
|
||||
- (c) += (ret<low)?1:0; \
|
||||
+ (c) += (ret<low); \
|
||||
(r) = ret; \
|
||||
}
|
||||
|
||||
@@ -556,7 +556,7 @@ unsigned __int64 _umul128(unsigned __int64 a, unsigned __int64 b,
|
||||
high= BN_UMULT_HIGH(w,ta); \
|
||||
ret = low + (c); \
|
||||
(c) = high; \
|
||||
- (c) += (ret<low)?1:0; \
|
||||
+ (c) += (ret<low); \
|
||||
(r) = ret; \
|
||||
}
|
||||
|
||||
@@ -589,10 +589,10 @@ unsigned __int64 _umul128(unsigned __int64 a, unsigned __int64 b,
|
||||
lt=(bl)*(lt); \
|
||||
m1=(bl)*(ht); \
|
||||
ht =(bh)*(ht); \
|
||||
- m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS((BN_ULONG)1); \
|
||||
+ m=(m+m1)&BN_MASK2; ht += L2HBITS((BN_ULONG)(m < m1)); \
|
||||
ht+=HBITS(m); \
|
||||
m1=L2HBITS(m); \
|
||||
- lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \
|
||||
+ lt=(lt+m1)&BN_MASK2; ht += (lt < m1); \
|
||||
(l)=lt; \
|
||||
(h)=ht; \
|
||||
}
|
||||
@@ -609,7 +609,7 @@ unsigned __int64 _umul128(unsigned __int64 a, unsigned __int64 b,
|
||||
h*=h; \
|
||||
h+=(m&BN_MASK2h1)>>(BN_BITS4-1); \
|
||||
m =(m&BN_MASK2l)<<(BN_BITS4+1); \
|
||||
- l=(l+m)&BN_MASK2; if (l < m) h++; \
|
||||
+ l=(l+m)&BN_MASK2; h += (l < m); \
|
||||
(lo)=l; \
|
||||
(ho)=h; \
|
||||
}
|
||||
@@ -623,9 +623,9 @@ unsigned __int64 _umul128(unsigned __int64 a, unsigned __int64 b,
|
||||
mul64(l,h,(bl),(bh)); \
|
||||
\
|
||||
/* non-multiply part */ \
|
||||
- l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
|
||||
+ l=(l+(c))&BN_MASK2; h += (l < (c)); \
|
||||
(c)=(r); \
|
||||
- l=(l+(c))&BN_MASK2; if (l < (c)) h++; \
|
||||
+ l=(l+(c))&BN_MASK2; h += (l < (c)); \
|
||||
(c)=h&BN_MASK2; \
|
||||
(r)=l; \
|
||||
}
|
||||
@@ -639,7 +639,7 @@ unsigned __int64 _umul128(unsigned __int64 a, unsigned __int64 b,
|
||||
mul64(l,h,(bl),(bh)); \
|
||||
\
|
||||
/* non-multiply part */ \
|
||||
- l+=(c); if ((l&BN_MASK2) < (c)) h++; \
|
||||
+ l+=(c); h += ((l&BN_MASK2) < (c)); \
|
||||
(c)=h&BN_MASK2; \
|
||||
(r)=l&BN_MASK2; \
|
||||
}
|
||||
@@ -669,7 +669,7 @@ BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
int cl, int dl);
|
||||
int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, int num);
|
||||
-
|
||||
+void bn_correct_top_consttime(BIGNUM *a);
|
||||
BIGNUM *int_bn_mod_inverse(BIGNUM *in,
|
||||
const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx,
|
||||
int *noinv);
|
||||
diff --git a/crypto/rsa/rsa_ossl.c b/crypto/rsa/rsa_ossl.c
|
||||
index 53cf2d03c9..cf5a10ab43 100644
|
||||
--- a/crypto/rsa/rsa_ossl.c
|
||||
+++ b/crypto/rsa/rsa_ossl.c
|
||||
@@ -226,6 +226,7 @@ static int rsa_blinding_invert(BN_BLINDING *b, BIGNUM *f, BIGNUM *unblind,
|
||||
* will only read the modulus from BN_BLINDING. In both cases it's safe
|
||||
* to access the blinding without a lock.
|
||||
*/
|
||||
+ BN_set_flags(f, BN_FLG_CONSTTIME);
|
||||
return BN_BLINDING_invert_ex(f, unblind, b, ctx);
|
||||
}
|
||||
|
||||
@@ -412,6 +413,11 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,
|
||||
goto err;
|
||||
}
|
||||
|
||||
+ if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
|
||||
+ if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,
|
||||
+ rsa->n, ctx))
|
||||
+ goto err;
|
||||
+
|
||||
if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) {
|
||||
blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
|
||||
if (blinding == NULL) {
|
||||
@@ -449,13 +455,6 @@ static int rsa_ossl_private_decrypt(int flen, const unsigned char *from,
|
||||
goto err;
|
||||
}
|
||||
BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
|
||||
-
|
||||
- if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
|
||||
- if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, rsa->lock,
|
||||
- rsa->n, ctx)) {
|
||||
- BN_free(d);
|
||||
- goto err;
|
||||
- }
|
||||
if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,
|
||||
rsa->_method_mod_n)) {
|
||||
BN_free(d);
|
||||
--
|
||||
2.27.0
|
||||
|
||||
|
@ -37,4 +37,5 @@ index d416d939ea..328c30cdbb 100644
|
||||
}
|
||||
BIO_read(headerB, *header, headerlen);
|
||||
--
|
||||
2.34.1
|
||||
2.17.1
|
||||
|
@ -0,0 +1,80 @@
|
||||
From f040f2577891d2bdb7610566c172233844cf673a Mon Sep 17 00:00:00 2001
|
||||
From: Matt Caswell <matt@openssl.org>
|
||||
Date: Wed, 14 Dec 2022 17:15:18 +0000
|
||||
Subject: [PATCH] Check CMS failure during BIO setup with -stream is handled
|
||||
correctly
|
||||
|
||||
Test for the issue fixed in the previous commit
|
||||
|
||||
Reviewed-by: Paul Dale <pauli@openssl.org>
|
||||
Reviewed-by: Tomas Mraz <tomas@openssl.org>
|
||||
---
|
||||
test/recipes/80-test_cms.t | 15 +++++++++++++--
|
||||
test/smime-certs/badrsa.pem | 18 ++++++++++++++++++
|
||||
2 files changed, 31 insertions(+), 2 deletions(-)
|
||||
create mode 100644 test/smime-certs/badrsa.pem
|
||||
|
||||
diff --git a/test/recipes/80-test_cms.t b/test/recipes/80-test_cms.t
|
||||
index 5dc6a3aebe..ec11bfc253 100644
|
||||
--- a/test/recipes/80-test_cms.t
|
||||
+++ b/test/recipes/80-test_cms.t
|
||||
@@ -13,7 +13,7 @@ use warnings;
|
||||
use POSIX;
|
||||
use File::Spec::Functions qw/catfile/;
|
||||
use File::Compare qw/compare_text/;
|
||||
-use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file/;
|
||||
+use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file with/;
|
||||
use OpenSSL::Test::Utils;
|
||||
|
||||
setup("test_cms");
|
||||
@@ -27,7 +27,7 @@ my $smcont = srctop_file("test", "smcont.txt");
|
||||
my ($no_des, $no_dh, $no_dsa, $no_ec, $no_ec2m, $no_rc2, $no_zlib)
|
||||
= disabled qw/des dh dsa ec ec2m rc2 zlib/;
|
||||
|
||||
-plan tests => 6;
|
||||
+plan tests => 7;
|
||||
|
||||
my @smime_pkcs7_tests = (
|
||||
|
||||
@@ -584,3 +584,14 @@ sub check_availability {
|
||||
|
||||
return "";
|
||||
}
|
||||
+
|
||||
+# Check that we get the expected failure return code
|
||||
+with({ exit_checker => sub { return shift == 6; } },
|
||||
+ sub {
|
||||
+ ok(run(app(['openssl', 'cms', '-encrypt',
|
||||
+ '-in', srctop_file("test", "smcont.txt"),
|
||||
+ '-stream', '-recip',
|
||||
+ srctop_file("test/smime-certs", "badrsa.pem"),
|
||||
+ ])),
|
||||
+ "Check failure during BIO setup with -stream is handled correctly");
|
||||
+ });
|
||||
diff --git a/test/smime-certs/badrsa.pem b/test/smime-certs/badrsa.pem
|
||||
new file mode 100644
|
||||
index 0000000000..f824fc2267
|
||||
--- /dev/null
|
||||
+++ b/test/smime-certs/badrsa.pem
|
||||
@@ -0,0 +1,18 @@
|
||||
+-----BEGIN CERTIFICATE-----
|
||||
+MIIDbTCCAlWgAwIBAgIToTV4Z0iuK08vZP20oTh//hC8BDANBgkqhkiG9w0BAQ0FADAtMSswKQYD
|
||||
+VfcDEyJTYW1wbGUgTEFNUFMgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MCAXDTE5MTEyMDA2NTQxOFoY
|
||||
+DzIwNTIwOTI3MDY1NDE4WjAZMRcwFQYDVQQDEw5BbGljZSBMb3ZlbGFjZTCCASIwDQYJKoZIhvcN
|
||||
+AQEBBQADggEPADCCAQoCggEBALT0iehYOBY+TZp/T5K2KNI05Hwr+E3wP6XTvyi6WWyTgBK9LCOw
|
||||
+I2juwdRrjFBmXkk7pWpjXwsA3A5GOtz0FpfgyC7OxsVcF7q4WHWZWleYXFKlQHJD73nQwXP968+A
|
||||
+/3rBX7PhO0DBbZnfitOLPgPEwjTtdg0VQQ6Wz+CRQ/YbHPKaw7aRphZO63dKvIKp4cQVtkWQHi6s
|
||||
+yTjGsgkLcLNau5LZDQUdsGV+SAo3nBdWCRYV+I65x8Kf4hCxqqmjV3d/2NKRu0BXnDe/N+iDz3X0
|
||||
+zEoj0fqXgq4SWcC0nsG1lyyXt1TL270I6ATKRGJWiQVCCpDtc0NT6vdJ45bCSxgCAwEAAaOBlzCB
|
||||
+lDAMBgNVHRMBAf8EAjAAMB4GA1UdEQQXMBWBE2FsaWNlQHNtaW1lLmV4YW1wbGUwEwYDVR0lBAww
|
||||
+CgYIKwYBBQUHAwQwDwYDVR0PAQH/BAUDAwfAADAdBgNVHQ4EFgQUu/bMsi0dBhIcl64papAQ0yBm
|
||||
+ZnMwHwYDVR0jBBgwFoAUeF8OWnjYa+RUcD2z3ez38fL6wEcwDQYJKoZIhvcNAQENBQADggEBABbW
|
||||
+eonR6TMTckehDKNOabwaCIcekahAIL6l9tTzUX5ew6ufiAPlC6I/zQlmUaU0iSyFDG1NW14kNbFt
|
||||
+5CAokyLhMtE4ASHBIHbiOp/ZSbUBTVYJZB61ot7w1/ol5QECSs08b8zrxIncf+t2DHGuVEy/Qq1d
|
||||
+rBz8d4ay8zpqAE1tUyL5Da6ZiKUfWwZQXSI/JlbjQFzYQqTRDnzHWrg1xPeMTO1P2/cplFaseTiv
|
||||
+yk4cYwOp/W9UAWymOZXF8WcJYCIUXkdcG/nEZxr057KlScrJmFXOoh7Y+8ON4iWYYcAfiNgpUFo/
|
||||
+j8BAwrKKaFvdlZS9k1Ypb2+UQY75mKJE9Bg=
|
||||
+-----END CERTIFICATE-----
|
||||
--
|
||||
2.17.1
|
||||
|
@ -102,4 +102,5 @@ index 760e4846a4..f8d4b1b9aa 100644
|
||||
OPENSSL_free(ndef_aux);
|
||||
return NULL;
|
||||
--
|
||||
2.34.1
|
||||
2.17.1
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user