10c6274a8SJohn Baldwin /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
30c6274a8SJohn Baldwin *
40c6274a8SJohn Baldwin * Copyright (c) 2021 The FreeBSD Foundation
50c6274a8SJohn Baldwin *
60c6274a8SJohn Baldwin * This software was developed by Ararat River Consulting, LLC under
70c6274a8SJohn Baldwin * sponsorship from the FreeBSD Foundation.
80c6274a8SJohn Baldwin *
90c6274a8SJohn Baldwin * Redistribution and use in source and binary forms, with or without
100c6274a8SJohn Baldwin * modification, are permitted provided that the following conditions
110c6274a8SJohn Baldwin * are met:
120c6274a8SJohn Baldwin * 1. Redistributions of source code must retain the above copyright
130c6274a8SJohn Baldwin * notice, this list of conditions and the following disclaimer.
140c6274a8SJohn Baldwin * 2. Redistributions in binary form must reproduce the above copyright
150c6274a8SJohn Baldwin * notice, this list of conditions and the following disclaimer in the
160c6274a8SJohn Baldwin * documentation and/or other materials provided with the distribution.
170c6274a8SJohn Baldwin *
180c6274a8SJohn Baldwin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
190c6274a8SJohn Baldwin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
200c6274a8SJohn Baldwin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
210c6274a8SJohn Baldwin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
220c6274a8SJohn Baldwin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
230c6274a8SJohn Baldwin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
240c6274a8SJohn Baldwin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
250c6274a8SJohn Baldwin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
260c6274a8SJohn Baldwin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
270c6274a8SJohn Baldwin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
280c6274a8SJohn Baldwin * SUCH DAMAGE.
290c6274a8SJohn Baldwin */
300c6274a8SJohn Baldwin
310c6274a8SJohn Baldwin #include <crypto/curve25519.h>
320c6274a8SJohn Baldwin #include <sodium/crypto_scalarmult_curve25519.h>
330c6274a8SJohn Baldwin
340c6274a8SJohn Baldwin bool
curve25519(uint8_t * public,const uint8_t * secret,const uint8_t * basepoint)350c6274a8SJohn Baldwin curve25519(uint8_t *public, const uint8_t *secret,
360c6274a8SJohn Baldwin const uint8_t *basepoint)
370c6274a8SJohn Baldwin {
380c6274a8SJohn Baldwin return (crypto_scalarmult_curve25519(public, secret,
390c6274a8SJohn Baldwin basepoint) == 0);
400c6274a8SJohn Baldwin }
410c6274a8SJohn Baldwin
420c6274a8SJohn Baldwin bool
curve25519_generate_public(uint8_t * public,const uint8_t * secret)430c6274a8SJohn Baldwin curve25519_generate_public(uint8_t *public, const uint8_t *secret)
440c6274a8SJohn Baldwin {
450c6274a8SJohn Baldwin return (crypto_scalarmult_curve25519_base(public, secret) == 0);
460c6274a8SJohn Baldwin }
47