interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / net / x25519.h

46 lines · 2013 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/* AIENOS X25519 (RFC 7748 Section 5), in C. No heap, clock or I/O.
18 *
19 * Why native/net and not native/sig: X25519 is only used here, for the M6-B
20 * handshake's ephemeral key agreement. native/sig is signatures (Ed25519 +
21 * SHA-512) owned by another lane; keeping X25519 next to its one caller
22 * avoids touching that tree. The field code is separate from ed25519.c on
23 * purpose (no shared internal header across lanes); if a second caller
24 * appears, move it to its own native/ecdh directory.
25 *
26 * Constant time with respect to the scalar: a fixed 255-step Montgomery
27 * ladder with masked conditional swaps, no secret-dependent branches or
28 * table indexes. Spot-checked by reading the AArch64 -O2 code, not measured.
29 */
30#ifndef AIENOS_X25519_H
31#define AIENOS_X25519_H
32
33#include <stdint.h>
34
35#define AIENOS_X25519_LEN 32
36
37/* out = X25519(scalar, u) per RFC 7748: the scalar is clamped and the top
38 * bit of u is masked, exactly as the RFC says. Always writes out. Returns 0
39 * normally, or -1 if out is the all-zero value (u was a small-order point);
40 * callers doing key agreement must refuse that case. out may alias u. */
41int aienos_x25519(uint8_t out[32], const uint8_t scalar[32], const uint8_t u[32]);
42
43/* out = X25519(scalar, 9): the public key for a secret scalar. */
44void aienos_x25519_base(uint8_t out[32], const uint8_t scalar[32]);
45
46#endif