1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef DEVICE_FIDO_EC_PUBLIC_KEY_H_ 6 #define DEVICE_FIDO_EC_PUBLIC_KEY_H_ 7 8 #include <stdint.h> 9 #include <memory> 10 #include <string> 11 #include <vector> 12 13 #include "base/component_export.h" 14 #include "base/containers/span.h" 15 #include "base/macros.h" 16 #include "device/fido/public_key.h" 17 18 namespace device { 19 20 // An uncompressed ECPublicKey consisting of 64 bytes: 21 // - the 32-byte x coordinate 22 // - the 32-byte y coordinate. COMPONENT_EXPORT(DEVICE_FIDO)23class COMPONENT_EXPORT(DEVICE_FIDO) ECPublicKey : public PublicKey { 24 public: 25 static std::unique_ptr<ECPublicKey> ExtractFromU2fRegistrationResponse( 26 std::string algorithm, 27 base::span<const uint8_t> u2f_data); 28 29 // Parse a public key encoded in ANSI X9.62 uncompressed format. 30 static std::unique_ptr<ECPublicKey> ParseX962Uncompressed( 31 std::string algorithm, 32 base::span<const uint8_t> input); 33 34 ECPublicKey(std::string algorithm, 35 std::vector<uint8_t> x, 36 std::vector<uint8_t> y); 37 38 ~ECPublicKey() override; 39 40 // Produces a key in COSE_key format, which is an integer-keyed CBOR map: 41 // { 1 ("kty") : 2 (the EC2 key id), 42 // 3 ("alg") : -7 (the ES256 COSEAlgorithmIdentifier), 43 // -1 ("crv"): 1 (the P-256 EC identifier), 44 // -2: x-coordinate, 45 // -3: y-coordinate } 46 std::vector<uint8_t> EncodeAsCOSEKey() const override; 47 48 private: 49 // Note that these values might not be minimal and might not be on the curve. 50 const std::vector<uint8_t> x_coordinate_; 51 const std::vector<uint8_t> y_coordinate_; 52 53 DISALLOW_COPY_AND_ASSIGN(ECPublicKey); 54 }; 55 56 } // namespace device 57 58 #endif // DEVICE_FIDO_EC_PUBLIC_KEY_H_ 59