blob: 4c1c3983d380507f9ee91fe3348ba515191cfd93 [file] [log] [blame]
Alice Wang3397b362023-12-01 13:57:10 +00001// Copyright 2023, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://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,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Wrappers of the Curve25519 related functions in BoringSSL curve25519.h.
16
17use crate::util::check_int_result;
18use bssl_avf_error::{ApiName, Result};
19
Maurice Lam0322b8c2023-12-18 22:13:48 +000020const ED25519_PUBLIC_KEY_LEN: usize = bssl_sys::ED25519_PUBLIC_KEY_LEN as usize;
21const ED25519_SIGNATURE_LEN: usize = bssl_sys::ED25519_SIGNATURE_LEN as usize;
Alice Wang3397b362023-12-01 13:57:10 +000022
23/// Verifies the signature of a message with the given ED25519 public key.
24pub fn ed25519_verify(
25 message: &[u8],
26 signature: &[u8; ED25519_SIGNATURE_LEN],
27 public_key: &[u8; ED25519_PUBLIC_KEY_LEN],
28) -> Result<()> {
29 // SAFETY: The function only reads the parameters within their bounds.
30 let ret = unsafe {
Maurice Lam0322b8c2023-12-18 22:13:48 +000031 bssl_sys::ED25519_verify(
Alice Wang3397b362023-12-01 13:57:10 +000032 message.as_ptr(),
33 message.len(),
34 signature.as_ptr(),
35 public_key.as_ptr(),
36 )
37 };
38 check_int_result(ret, ApiName::ED25519_verify)
39}