1 // 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 
17 use crate::util::check_int_result;
18 use bssl_avf_error::{ApiName, Result};
19 
20 const ED25519_PUBLIC_KEY_LEN: usize = bssl_sys::ED25519_PUBLIC_KEY_LEN as usize;
21 const ED25519_SIGNATURE_LEN: usize = bssl_sys::ED25519_SIGNATURE_LEN as usize;
22 
23 /// Verifies the signature of a message with the given ED25519 public key.
ed25519_verify( message: &[u8], signature: &[u8; ED25519_SIGNATURE_LEN], public_key: &[u8; ED25519_PUBLIC_KEY_LEN], ) -> Result<()>24 pub 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 {
31         bssl_sys::ED25519_verify(
32             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 }
40