Skip to content

Commit

Permalink
Improved support for OpenSSH (aws#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth authored Apr 10, 2023
1 parent 927fe07 commit ea33bd9
Show file tree
Hide file tree
Showing 18 changed files with 553 additions and 459 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
DerivePointerAlignment: false
PointerAlignment: Right
InsertBraces: true
# TODO(davidben): The default for Google style is now Regroup, but the default
# IncludeCategories does not recognize <openssl/header.h>. We should
# reconfigure IncludeCategories to match. For now, keep it at Preserve.
Expand Down
2 changes: 2 additions & 0 deletions crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ if(BUILD_TESTING)
target_link_libraries(${CRYPTO_TEST_EXEC} test_support_lib boringssl_gtest_main crypto)
if(WIN32)
target_link_libraries(${CRYPTO_TEST_EXEC} ws2_32)
else()
target_compile_options(${CRYPTO_TEST_EXEC} PUBLIC -Wno-deprecated-declarations)
endif()
add_dependencies(all_tests ${CRYPTO_TEST_EXEC})
endif()
Expand Down
45 changes: 44 additions & 1 deletion crypto/ec_extra/ec_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
Expand Down Expand Up @@ -532,3 +532,46 @@ int i2o_ECPublicKey(const EC_KEY *key, uint8_t **outp) {
// Historically, this function used the wrong return value on error.
return ret > 0 ? ret : 0;
}

static size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point,
point_conversion_form_t form,
uint8_t **pbuf, BN_CTX *ctx) {
size_t len;
uint8_t *buf;

len = EC_POINT_point2oct(group, point, form, NULL, 0, NULL);
if (len == 0) {
return 0;
}
buf = OPENSSL_malloc(len);
if (buf == NULL) {
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
return 0;
}
len = EC_POINT_point2oct(group, point, form, buf, len, ctx);
if (len == 0) {
OPENSSL_free(buf);
return 0;
}
*pbuf = buf;
return len;
}

BIGNUM *EC_POINT_point2bn(const EC_GROUP *group, const EC_POINT *point,
point_conversion_form_t form, BIGNUM *ret,
BN_CTX *ctx) {
size_t buf_len = 0;
uint8_t *buf;

buf_len = EC_POINT_point2buf(group, point, form, &buf, ctx);

if (buf_len == 0) {
return NULL;
}

ret = BN_bin2bn(buf, buf_len, ret);

OPENSSL_free(buf);

return ret;
}
2 changes: 2 additions & 0 deletions crypto/err/err.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,8 @@ int ERR_pop_to_mark(void) {
return 0;
}

void ERR_load_CRYPTO_strings(void) {}

void ERR_load_crypto_strings(void) {}

void ERR_free_strings(void) {}
Expand Down
1 change: 1 addition & 0 deletions crypto/err/evp.errordata
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
EVP,138,BAD_DECRYPT
EVP,100,BUFFER_TOO_SMALL
EVP,101,COMMAND_NOT_SUPPORTED
EVP,102,DECODE_ERROR
Expand Down
1 change: 1 addition & 0 deletions crypto/err/pem.errordata
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PEM,107,NOT_DEK_INFO
PEM,108,NOT_ENCRYPTED
PEM,109,NOT_PROC_TYPE
PEM,110,NO_START_LINE
PEM,115,PROBLEMS_GETTING_PASSWORD
PEM,111,READ_KEY
PEM,112,SHORT_HEADER
PEM,113,UNSUPPORTED_CIPHER
Expand Down
24 changes: 22 additions & 2 deletions crypto/fipsmodule/ec/ec_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <openssl/bn.h>
#include <openssl/bytestring.h>
#include <openssl/crypto.h>
#include <openssl/ec.h>
#include <openssl/ec_key.h>
#include <openssl/err.h>
#include <openssl/mem.h>
Expand Down Expand Up @@ -1036,6 +1037,25 @@ TEST(ECTest, ArbitraryCurve) {
EXPECT_EQ(0, EC_GROUP_cmp(group.get(), group.get(), NULL));
EXPECT_EQ(0, EC_GROUP_cmp(group2.get(), group.get(), NULL));

bssl::UniquePtr<BIGNUM> converted_generator1(EC_POINT_point2bn(
group.get(), generator.get(), POINT_CONVERSION_UNCOMPRESSED, NULL, NULL));
ASSERT_TRUE(converted_generator1);

bssl::UniquePtr<BIGNUM> converted_generator2(EC_POINT_point2bn(
group2.get(), generator2.get(), POINT_CONVERSION_UNCOMPRESSED, NULL, NULL));
ASSERT_TRUE(converted_generator2);
EXPECT_EQ(0, BN_cmp(converted_generator1.get(), converted_generator2.get()));

bssl::UniquePtr<BIGNUM> converted_generator3(EC_POINT_point2bn(
group.get(), generator.get(), POINT_CONVERSION_COMPRESSED, NULL, NULL));
ASSERT_TRUE(converted_generator3);

bssl::UniquePtr<BIGNUM> converted_generator4(EC_POINT_point2bn(
group2.get(), generator2.get(), POINT_CONVERSION_COMPRESSED, NULL, NULL));
ASSERT_TRUE(converted_generator4);
EXPECT_EQ(0, BN_cmp(converted_generator3.get(), converted_generator4.get()));


// group3 uses the wrong generator.
bssl::UniquePtr<EC_GROUP> group3(
EC_GROUP_new_curve_GFp(p.get(), a.get(), b.get(), ctx.get()));
Expand Down Expand Up @@ -1829,8 +1849,8 @@ static int has_uint128_and_not_small() {
}

// Test for out-of-range coordinates in public-key validation in
// |EC_KEY_check_fips|. This test can only be exercised when the coordinates
// in the raw point are not in Montgomery representation, which is the case
// |EC_KEY_check_fips|. This test can only be exercised when the coordinates
// in the raw point are not in Montgomery representation, which is the case
// for P-224 in some builds (see below) and for P-521.
TEST(ECTest, LargeXCoordinateVectors) {
int line;
Expand Down
1 change: 0 additions & 1 deletion crypto/obj/obj_dat.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

/* This file is generated by crypto/obj/objects.go. */


#define NUM_NID 975

static const uint8_t kObjectData[] = {
Expand Down
2 changes: 1 addition & 1 deletion crypto/obj/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func writeNumbers(path string, objs *objects) error {

func clangFormat(input string) (string, error) {
var b bytes.Buffer
cmd := exec.Command("clang-format")
cmd := exec.Command("clang-format", "--style=Google")
cmd.Stdin = strings.NewReader(input)
cmd.Stdout = &b
cmd.Stderr = os.Stderr
Expand Down
Loading

0 comments on commit ea33bd9

Please sign in to comment.