interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / searchtrace / sig / aienos_sig.h

70 lines · 2946 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 in-house signatures in C: Ed25519 (RFC 8032 Section 5.1, pure
18 * Ed25519 only: no Ed25519ph, no Ed25519ctx) and SHA-512 (FIPS 180-4).
19 *
20 * No heap, no clock, no I/O. Signing and public-key derivation are written
21 * to run in constant time with respect to the secret key and the nonce.
22 * Verification handles only public data and is NOT constant time.
23 */
24#ifndef AIENOS_SIG_H
25#define AIENOS_SIG_H
26
27#include <stddef.h>
28#include <stdint.h>
29
30#define AIENOS_SIG_OK 0
31#define AIENOS_SIG_ERR_INVALID (-1) /* signature or public key rejected */
32#define AIENOS_SIG_ERR_ARG (-2) /* NULL buffer */
33
34#define AIENOS_ED25519_SECRET_KEY_LEN 32
35#define AIENOS_ED25519_PUBLIC_KEY_LEN 32
36#define AIENOS_ED25519_SIGNATURE_LEN 64
37
38/* SHA-512 */
39#define AIENOS_SHA512_DIGEST_LEN 64
40typedef struct {
41 uint64_t h[8];
42 uint64_t bytes; /* total bytes absorbed (messages up to 2^64 - 1 bytes) */
43 uint8_t buf[128];
44 size_t n; /* bytes waiting in buf */
45} aienos_sha512_ctx;
46
47void aienos_sha512_init(aienos_sha512_ctx *c);
48void aienos_sha512_update(aienos_sha512_ctx *c, const uint8_t *p, size_t len);
49/* Writes the digest and wipes the context. */
50void aienos_sha512_final(aienos_sha512_ctx *c, uint8_t out[AIENOS_SHA512_DIGEST_LEN]);
51void aienos_sha512(const uint8_t *p, size_t len, uint8_t out[AIENOS_SHA512_DIGEST_LEN]);
52
53/* Ed25519. sk is the 32-byte RFC 8032 secret key (seed). */
54int aienos_ed25519_public_key(uint8_t pk[32], const uint8_t sk[32]);
55
56/* Derives the public key from sk itself (no caller-supplied public key, so
57 * a mismatched pair cannot leak the key). msg may be NULL when msg_len is 0.
58 * sig may overlap msg. */
59int aienos_ed25519_sign(uint8_t sig[64], const uint8_t *msg, size_t msg_len,
60 const uint8_t sk[32]);
61
62/* Returns AIENOS_SIG_OK only if sig is a valid signature of msg under pk.
63 * Rejects (AIENOS_SIG_ERR_INVALID): S >= L, a non-canonical or off-curve
64 * encoding of A or R, x = 0 with the sign bit set, and A or R of small order
65 * (order dividing 8). Equation checked: encode([S]B - [k]A) == R bytes
66 * (cofactorless, RFC 8032 Section 5.1.7 without the optional factor 8). */
67int aienos_ed25519_verify(const uint8_t sig[64], const uint8_t *msg, size_t msg_len,
68 const uint8_t pk[32]);
69
70#endif