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 #pragma once 16 17 #include "pw_bytes/span.h" 18 #include "pw_status/status.h" 19 20 namespace pw::crypto::ecdsa { 21 22 /// Verifies the `signature` of `digest` using `public_key`. 23 /// 24 /// Example: 25 /// 26 /// @code{.cpp} 27 /// #include "pw_crypto/sha256.h" 28 /// 29 /// // Verify a digital signature signed with ECDSA over the NIST P256 curve. 30 /// std::byte digest[32]; 31 /// if (!pw::crypto::sha256::Hash(message, digest).ok()) { 32 /// // handle errors. 33 /// } 34 /// 35 /// if (!pw::crypto::ecdsa::VerifyP256Signature(public_key, digest, 36 /// signature).ok()) { 37 /// // handle errors. 38 /// } 39 /// @endcode 40 /// 41 /// @param[in] public_key A byte string in SEC 1 uncompressed form 42 /// ``(0x04||X||Y)``, which is exactly 65 bytes. Compressed forms 43 /// ``(02/03||X)`` *may* not be supported by some backends, e.g. Mbed TLS. 44 /// 45 /// @param[in] digest A raw byte string, truncated to 32 bytes. 46 /// 47 /// @param[in] signature A raw byte string ``(r||s)`` of exactly 64 bytes. 48 /// 49 /// @returns @pw_status{OK} for a successful verification, or an error 50 /// ``Status`` otherwise. 51 Status VerifyP256Signature(ConstByteSpan public_key, 52 ConstByteSpan digest, 53 ConstByteSpan signature); 54 55 } // namespace pw::crypto::ecdsa 56