ECDSA_verify does a runtime check that our parser round-trips, but that should already be true. Add a fuzzer to ensure it. Change-Id: I396863b8f9ed66c6296cfb16f7197a63ae99e156 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/52733 Reviewed-by: Adam Langley <agl@google.com>chromium-5359
parent
a255d7c6a1
commit
505bbf9c84
81 changed files with 87 additions and 0 deletions
@ -0,0 +1,57 @@ |
||||
/* Copyright (c) 2022, Google Inc.
|
||||
* |
||||
* Permission to use, copy, modify, and/or distribute this software for any |
||||
* purpose with or without fee is hereby granted, provided that the above |
||||
* copyright notice and this permission notice appear in all copies. |
||||
* |
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
||||
|
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
|
||||
#include <openssl/bytestring.h> |
||||
#include <openssl/ecdsa.h> |
||||
#include <openssl/mem.h> |
||||
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) { |
||||
CBS cbs, body; |
||||
unsigned tag; |
||||
CBS_init(&cbs, buf, len); |
||||
if (CBS_get_any_asn1(&cbs, &body, &tag)) { |
||||
// DER has a unique encoding, so any parsed input should round-trip
|
||||
// correctly.
|
||||
size_t consumed = len - CBS_len(&cbs); |
||||
bssl::ScopedCBB cbb; |
||||
CBB body_cbb; |
||||
if (!CBB_init(cbb.get(), consumed) || |
||||
!CBB_add_asn1(cbb.get(), &body_cbb, tag) || |
||||
!CBB_add_bytes(&body_cbb, CBS_data(&body), CBS_len(&body)) || |
||||
!CBB_flush(cbb.get()) || |
||||
CBB_len(cbb.get()) != consumed || |
||||
memcmp(CBB_data(cbb.get()), buf, consumed) != 0) { |
||||
abort(); |
||||
} |
||||
} |
||||
|
||||
ECDSA_SIG *sig = ECDSA_SIG_from_bytes(buf, len); |
||||
if (sig != NULL) { |
||||
uint8_t *enc; |
||||
size_t enc_len; |
||||
if (!ECDSA_SIG_to_bytes(&enc, &enc_len, sig) || |
||||
enc_len != len || |
||||
memcmp(buf, enc, len) != 0) { |
||||
abort(); |
||||
} |
||||
OPENSSL_free(enc); |
||||
ECDSA_SIG_free(sig); |
||||
} |
||||
|
||||
return 0; |
||||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@ |
||||
? |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@ |
||||
3 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@ |
||||
@@ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@ |
||||
wはウ |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue