Skip to content

Commit

Permalink
Update points-to preconditions for ec_group_st and ec_method_st (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
pennyannn authored Nov 22, 2023
1 parent b519d2e commit bde06b0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "src"]
path = src
branch = main
url = https://github.com/aws/aws-lc.git
branch = upstream-merge-2023-11-20
url = https://github.com/torben-hansen/aws-lc.git
[submodule "cryptol-specs"]
path = cryptol-specs
branch = sha-imperative
Expand Down
18 changes: 18 additions & 0 deletions SAW/proof/BN/BN.saw
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ let pointer_to_bn_mont_ctx_st num N = do {
return (RR_d_ptr, ptr);
};

let points_to_bn_mont_ctx_st ptr num N = do {
let num_bits = eval_size {| num * 64 |};
let RR_bn_dmax = eval_size {| 2 * num + 1 |};
let R = {{ 2 ^^ `num_bits }};

RR_d_ptr <- crucible_alloc_readonly (llvm_int num_bits);
crucible_points_to RR_d_ptr (crucible_term {{ (fromInteger ((R * R) % `N)) : [num_bits] }});
points_to_bignum_st (crucible_field ptr "RR") RR_d_ptr num RR_bn_dmax {{ 0 : [32] }};

let n0 = eval_int {{ bn_mont_n0`{N} }};
crucible_points_to_untyped (crucible_field ptr "n0") (crucible_term {{ `n0 : [64] }});

N_d_ptr <- crucible_alloc_readonly (llvm_int num_bits);
crucible_points_to N_d_ptr (crucible_term {{ (fromInteger `N) : [num_bits] }});
points_to_bignum_st (crucible_field ptr "N") N_d_ptr num num {{ 0 : [32] }};
};


let {{
bn_mont_n0_with_N : {a} (fin a) => [a][64] -> [64]
bn_mont_n0_with_N n = undefined
Expand Down
14 changes: 2 additions & 12 deletions SAW/proof/EC/EC.saw
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ let points_to_AWSLC_fips_evp_pkey_methods = do {


let points_to_ec_method_st ptr = do {
crucible_points_to (crucible_field ptr "group_init") (crucible_global "ec_GFp_mont_group_init");
crucible_points_to (crucible_field ptr "group_finish") (crucible_global "ec_GFp_mont_group_finish");
crucible_points_to (crucible_field ptr "group_set_curve") (crucible_global "ec_GFp_mont_group_set_curve");
crucible_points_to (crucible_field ptr "point_get_affine_coordinates") (crucible_global "ec_GFp_mont_point_get_affine_coordinates");
crucible_points_to (crucible_field ptr "jacobian_to_affine_batch") (crucible_global "ec_GFp_mont_jacobian_to_affine_batch");
crucible_points_to (crucible_field ptr "add") (crucible_global "ec_GFp_mont_add");
Expand Down Expand Up @@ -151,21 +148,14 @@ let pointer_to_fresh_ec_group_st_with_curve_name curve_name = do {

crucible_points_to (crucible_field ptr "curve_name") (crucible_term {{ `curve_name : [32] }});

(_, order_mont_ptr) <- pointer_to_bn_mont_ctx_st ec_words {| P384_n |};
crucible_points_to (crucible_field ptr "order") order_mont_ptr;

field_d_ptr <- crucible_alloc_readonly i384;
crucible_points_to field_d_ptr (crucible_term {{ fromInteger`{[P384_w]} `P384_p }});
points_to_p384_bignum_st (crucible_field ptr "field") field_d_ptr {{ 0 : [32] }};
points_to_bn_mont_ctx_st (crucible_field ptr "order") ec_words {| P384_n |};
points_to_bn_mont_ctx_st (crucible_field ptr "field") ec_words {| P384_p |};

crucible_points_to_untyped (crucible_field ptr "a") (crucible_term {{ fieldElementToBV ((P384_a * P384_R_p) % `P384_p) }});
crucible_points_to_untyped (crucible_field ptr "b") (crucible_term {{ fieldElementToBV ((P384_b * P384_R_p) % `P384_p) }});
crucible_points_to (crucible_field ptr "a_is_minus3") (crucible_term {{ 1 : [32] }});
crucible_points_to (crucible_field ptr "field_greater_than_order") (crucible_term {{ 1 : [32] }});

(_, mont_ptr) <- pointer_to_bn_mont_ctx_st ec_words {| P384_p |};
crucible_points_to (crucible_field ptr "mont") mont_ptr;

crucible_points_to_untyped (crucible_field ptr "one") (crucible_term {{ fieldElementToBV P384_R_p }});

return ptr;
Expand Down
12 changes: 4 additions & 8 deletions SAW/proof/EC/EC_P384_private.saw
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "../../spec/EC/EC_P384_5.cry";
include "../common/helpers.saw";
include "../common/internal.saw";
include "EC_P384_primitives.saw";
include "../BN/BN.saw";

let limb_length = 64;
let p384_felem_limbs = 6;
Expand Down Expand Up @@ -197,19 +198,14 @@ ec_compute_wNAF_in_range_lemma <-
(w4_unint_z3 [])
(rewrite (cryptol_ss ()) {{ \scalar -> ec_compute_wNAF_in_range (ec_compute_wNAF scalar) }});

let points_to_ec_group_st_initialized_order_width ptr width = do {
order_mont_ptr <- crucible_alloc_readonly (llvm_struct "struct.bn_mont_ctx_st");
crucible_points_to (crucible_field (crucible_field order_mont_ptr "N") "width") width;
crucible_points_to (crucible_field ptr "order") order_mont_ptr;
};

let ec_compute_wNAF_out = "ec_compute_wNAF.out";
let ec_compute_wNAF_range = "ec_compute_wNAF.range";

let ec_compute_wNAF_spec w order_width = do {

group_ptr <- crucible_alloc_readonly (llvm_struct "struct.ec_group_st");
points_to_ec_group_st_initialized_order_width group_ptr (crucible_term {{ `order_width : [32] }});
points_to_bn_mont_ctx_st (crucible_field group_ptr "order") order_width {| P384_n |};
out_ptr <- crucible_alloc (llvm_array 385 i8);
(scalar, scalar_ptr) <- ptr_to_fresh_readonly "scalar" i384;

Expand Down Expand Up @@ -291,7 +287,7 @@ let ec_GFp_nistp384_point_mul_public_loop_spec = do {

// pointer to group
group_ptr <- crucible_alloc_readonly (llvm_struct "struct.ec_group_st");
points_to_ec_group_st_initialized_order_width group_ptr (crucible_term {{ `p384_felem_limbs : [32] }});
points_to_bn_mont_ctx_st (crucible_field group_ptr "order") p384_felem_limbs {| P384_n |};
group_pp <- llvm_alloc (llvm_int 64);
llvm_points_to group_pp group_ptr;

Expand Down Expand Up @@ -452,7 +448,7 @@ let p384_point_mul_public_spec order_width = do {
global_alloc_init "OPENSSL_ia32cap_P" {{ ia32cap }};

group_ptr <- crucible_alloc_readonly (llvm_struct "struct.ec_group_st");
points_to_ec_group_st_initialized_order_width group_ptr (crucible_term {{ `order_width : [32] }});
points_to_bn_mont_ctx_st (crucible_field group_ptr "order") order_width {| P384_n |};
r_ptr <- crucible_alloc (llvm_struct "struct.EC_JACOBIAN");
(g_scalar, g_scalar_ptr) <- ptr_to_fresh_readonly "g_scalar" i384;
p_ptr <- crucible_alloc_readonly (llvm_struct "struct.EC_JACOBIAN");
Expand Down
4 changes: 4 additions & 0 deletions SAW/proof/EC/verify-P384.saw
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

enable_experimental;

Expand Down
2 changes: 1 addition & 1 deletion src
Submodule src updated 81 files
+13 −0 .github/codecov.yml
+23 −0 .github/workflows/codecov-ci.yml
+3 −2 CMakeLists.txt
+6 −0 cmake/go.cmake
+1 −0 crypto/CMakeLists.txt
+9 −0 crypto/crypto_test.cc
+33 −33 crypto/curve25519/curve25519.c
+9 −9 crypto/curve25519/curve25519_nohw.c
+1 −11 crypto/curve25519/internal.h
+2 −2 crypto/ec_extra/ec_derive.c
+6 −6 crypto/ec_extra/hash_to_curve.c
+1 −1 crypto/ecdh_extra/ecdh_test.cc
+77 −0 crypto/fipsmodule/bn/bn_assert_test.cc
+17 −0 crypto/fipsmodule/bn/bytes.c
+8 −1 crypto/fipsmodule/bn/internal.h
+13 −7 crypto/fipsmodule/bn/montgomery.c
+28 −50 crypto/fipsmodule/ec/ec.c
+4 −4 crypto/fipsmodule/ec/ec_key.c
+19 −54 crypto/fipsmodule/ec/ec_montgomery.c
+9 −9 crypto/fipsmodule/ec/ec_test.cc
+12 −13 crypto/fipsmodule/ec/felem.c
+10 −28 crypto/fipsmodule/ec/internal.h
+18 −17 crypto/fipsmodule/ec/oct.c
+0 −3 crypto/fipsmodule/ec/p224-64.c
+12 −15 crypto/fipsmodule/ec/p256-nistz.c
+3 −6 crypto/fipsmodule/ec/p256.c
+5 −8 crypto/fipsmodule/ec/p384.c
+0 −3 crypto/fipsmodule/ec/p521.c
+24 −26 crypto/fipsmodule/ec/scalar.c
+9 −26 crypto/fipsmodule/ec/simple.c
+4 −4 crypto/fipsmodule/ec/simple_mul.c
+2 −2 crypto/fipsmodule/ec/wnaf.c
+3 −3 crypto/trust_token/pmbtoken.c
+6 −8 crypto/trust_token/trust_token_test.cc
+5 −5 crypto/trust_token/voprf.c
+2 −0 crypto/x509v3/v3_lib.c
+28 −11 include/openssl/base.h
+2 −2 include/openssl/cipher.h
+1 −1 include/openssl/ec.h
+1 −1 include/openssl/err.h
+3 −2 include/openssl/x509v3.h
+10 −0 tests/ci/cdk/cdk/codebuild/github_ci_integration_omnibus.yaml
+1 −0 tests/ci/docker_images/linux-x86/ubuntu-22.04_base/Dockerfile
+56 −0 tests/ci/integration/run_monit_integration.sh
+284 −0 third_party/s2n-bignum/arm/curve25519/bignum_madd_n25519.S
+210 −0 third_party/s2n-bignum/arm/curve25519/bignum_madd_n25519_alt.S
+186 −0 third_party/s2n-bignum/arm/curve25519/bignum_mod_n25519.S
+65 −0 third_party/s2n-bignum/arm/curve25519/bignum_neg_p25519.S
+1,043 −352 third_party/s2n-bignum/arm/curve25519/curve25519_x25519.S
+1,043 −352 third_party/s2n-bignum/arm/curve25519/curve25519_x25519_alt.S
+1,043 −352 third_party/s2n-bignum/arm/curve25519/curve25519_x25519_byte.S
+1,043 −352 third_party/s2n-bignum/arm/curve25519/curve25519_x25519_byte_alt.S
+1,042 −352 third_party/s2n-bignum/arm/curve25519/curve25519_x25519base.S
+1,042 −352 third_party/s2n-bignum/arm/curve25519/curve25519_x25519base_alt.S
+1,042 −352 third_party/s2n-bignum/arm/curve25519/curve25519_x25519base_byte.S
+1,043 −354 third_party/s2n-bignum/arm/curve25519/curve25519_x25519base_byte_alt.S
+700 −0 third_party/s2n-bignum/arm/curve25519/edwards25519_decode.S
+563 −0 third_party/s2n-bignum/arm/curve25519/edwards25519_decode_alt.S
+131 −0 third_party/s2n-bignum/arm/curve25519/edwards25519_encode.S
+9,626 −0 third_party/s2n-bignum/arm/curve25519/edwards25519_scalarmulbase.S
+9,468 −0 third_party/s2n-bignum/arm/curve25519/edwards25519_scalarmulbase_alt.S
+3,157 −0 third_party/s2n-bignum/arm/curve25519/edwards25519_scalarmuldouble.S
+2,941 −0 third_party/s2n-bignum/arm/curve25519/edwards25519_scalarmuldouble_alt.S
+1 −1 third_party/s2n-bignum/arm/p384/Makefile
+1 −1 third_party/s2n-bignum/arm/p521/Makefile
+219 −0 third_party/s2n-bignum/x86_att/curve25519/bignum_madd_n25519.S
+245 −0 third_party/s2n-bignum/x86_att/curve25519/bignum_madd_n25519_alt.S
+228 −0 third_party/s2n-bignum/x86_att/curve25519/bignum_mod_n25519.S
+86 −0 third_party/s2n-bignum/x86_att/curve25519/bignum_neg_p25519.S
+1,350 −407 third_party/s2n-bignum/x86_att/curve25519/curve25519_x25519.S
+1,350 −407 third_party/s2n-bignum/x86_att/curve25519/curve25519_x25519_alt.S
+1,344 −400 third_party/s2n-bignum/x86_att/curve25519/curve25519_x25519base.S
+1,348 −402 third_party/s2n-bignum/x86_att/curve25519/curve25519_x25519base_alt.S
+670 −0 third_party/s2n-bignum/x86_att/curve25519/edwards25519_decode.S
+751 −0 third_party/s2n-bignum/x86_att/curve25519/edwards25519_decode_alt.S
+81 −0 third_party/s2n-bignum/x86_att/curve25519/edwards25519_encode.S
+9,910 −0 third_party/s2n-bignum/x86_att/curve25519/edwards25519_scalarmulbase.S
+9,986 −0 third_party/s2n-bignum/x86_att/curve25519/edwards25519_scalarmulbase_alt.S
+3,619 −0 third_party/s2n-bignum/x86_att/curve25519/edwards25519_scalarmuldouble.S
+3,736 −0 third_party/s2n-bignum/x86_att/curve25519/edwards25519_scalarmuldouble_alt.S
+82 −0 util/codecov-ci.sh

0 comments on commit bde06b0

Please sign in to comment.