• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include <cstring>
16 
17 #include "pw_bloat/bloat_this_binary.h"
18 #include "pw_crypto/ecdsa.h"
19 
20 namespace {
21 #define STR_TO_BYTES(s) std::as_bytes(std::span(s, sizeof(s) - 1))
22 
23 // The SHA256 digest of "Hello, Pigweed!", 32 bytes.
24 #define DIGEST                                                       \
25   "\x8D\xCE\x14\xEE\x2C\xD9\xFD\x9B\xBD\x8C\x8D\x57\x68\x50\x2C\x2F" \
26   "\xFB\xB3\x52\x36\xCE\x93\x47\x1B\x80\xFC\xA4\x7D\xB5\xF8\x41\x9D"
27 
28 // The public key in uncompressed form, 65 bytes.
29 #define PUBKEY                                                       \
30   "\x04"                                                             \
31   "\xD1\x82\x2E\x6A\xD2\x4B\x2A\x80\x2E\x8F\xBC\x03\x00\x95\x11\xF9" \
32   "\x81\x24\xA7\x3C\x45\xC8\xBA\xDD\x5F\x77\x1C\xC3\x71\x8B\xB2\xE9" \
33   "\x3A\x0A\x84\xFF\xEA\x13\xC2\x27\xD2\xCF\x42\x7D\xA5\x95\xD6\x88" \
34   "\xCD\x23\x00\x3F\xF9\xD9\x75\x46\xFF\x58\xE9\xBE\xC3\x74\x13\xB8"
35 
36 // The ECDSA P256 signature of `DIGEST`.
37 #define SIGNATURE                                                    \
38   "\x16\x54\x43\xD4\x00\x07\xC4\xD7\x26\x2E\x3C\xB1\x65\x54\x00\x6A" \
39   "\x6A\x5B\x4A\xBB\x16\x6F\x44\xD0\x91\x3F\xD3\xC2\x50\xAC\x1A\x87" \
40   "\x86\x41\xEE\x56\xDA\x31\xF2\xFF\x38\x3C\xBB\x32\x3E\x2D\xDB\x98" \
41   "\xEA\x05\x9E\x8F\x91\x8E\x0E\x99\xE5\x4F\x32\x13\x92\x7F\x17\x68"
42 }  // namespace
43 
main()44 int main() {
45   pw::bloat::BloatThisBinary();
46 
47   pw::crypto::ecdsa::VerifyP256Signature(
48       STR_TO_BYTES(PUBKEY), STR_TO_BYTES(DIGEST), STR_TO_BYTES(SIGNATURE));
49   return 0;
50 }
51