Lux GPU Core 0.2.0
Lightweight plugin-based GPU acceleration for blockchain and ML
Loading...
Searching...
No Matches
crypto.h
Go to the documentation of this file.
1// Copyright (c) 2024-2026 Lux Industries Inc.
2// SPDX-License-Identifier: BSD-3-Clause-Eco
3//
4// Lux GPU crypto types
5//
6// Shared types for cryptographic kernels (MSM, KZG, Poseidon2, Shamir, ...).
7// The curve enum lives in <lux/gpu.h> as LuxCurve and is the single source of
8// truth — int curve_type fields in the vtbl ABI are LuxCurve values cast to int.
9
10#ifndef LUX_GPU_CRYPTO_H
11#define LUX_GPU_CRYPTO_H
12
13#include <stdint.h>
14#include <stddef.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20// =============================================================================
21// Field Types
22// =============================================================================
23
24// 256-bit scalar (BN254 base/scalar, BLS12-381 scalar, secp256k1, ed25519)
25typedef struct {
26 uint64_t limbs[4];
28
29// 384-bit base field element (BLS12-381)
30typedef struct {
31 uint64_t limbs[6];
32} LuxFp384;
33
34// 64-bit Goldilocks field element (2^64 - 2^32 + 1)
35typedef uint64_t LuxGoldilocks;
36
37// =============================================================================
38// Point Types
39// =============================================================================
40
41// G1 affine point (BN254) — Fp254 is encoded as 4×u64 to match shader layout
42typedef struct {
45 uint32_t infinity;
46 uint32_t _pad;
48
49// G1 projective (Jacobian) point (BN254)
55
56// G1 affine point (BLS12-381) — Fp384 is 6×u64
57typedef struct {
60 uint32_t infinity;
61 uint32_t _pad;
63
64// G1 projective (Jacobian) point (BLS12-381)
70
71// 768-bit quadratic-extension element Fp2 = Fp[u]/(u² + 1). Layout matches
72// blst's `blst_fp2 { blst_fp fp[2]; }` byte-for-byte: c0 first, then c1.
73// All limbs are in Montgomery form (R = 2^384 mod p), same convention as
74// LuxFp384.
75typedef struct {
79
80// G2 affine point on the BLS12-381 sextic twist E'(Fp2): y² = x³ + 4(1+u).
81// Layout matches blst's `blst_p2_affine { blst_fp2 x, y; }` and adds the
82// infinity flag word for ABI symmetry with LuxG1Affine381.
83typedef struct {
86 uint32_t infinity;
87 uint32_t _pad;
89
90// G2 projective (Jacobian) point. Layout matches blst's
91// `blst_p2 { blst_fp2 x, y, z; }`.
97
98// Fp12 element — the pairing target group GT lives here. Layout matches
99// blst byte-for-byte: 12 Fp limbs grouped as c0 ‖ c1 with c_i = Fp6 =
100// (Fp2)³. Total size = 576 bytes (12 × 6 × u64).
101typedef struct {
104
105// =============================================================================
106// Error Codes
107// =============================================================================
108
118
119#ifdef __cplusplus
120}
121#endif
122
123#endif // LUX_GPU_CRYPTO_H
uint64_t LuxGoldilocks
Definition crypto.h:35
LuxCryptoError
Definition crypto.h:109
@ LUX_CRYPTO_ERROR_INVALID_CURVE
Definition crypto.h:114
@ LUX_CRYPTO_ERROR_OUT_OF_MEMORY
Definition crypto.h:112
@ LUX_CRYPTO_ERROR_INVALID_ARG
Definition crypto.h:111
@ LUX_CRYPTO_OK
Definition crypto.h:110
@ LUX_CRYPTO_ERROR_NOT_SUPPORTED
Definition crypto.h:113
@ LUX_CRYPTO_ERROR_INVALID_POINT
Definition crypto.h:115
@ LUX_CRYPTO_ERROR_DEVICE_ERROR
Definition crypto.h:116
LuxFp384 c1
Definition crypto.h:77
LuxFp384 c0
Definition crypto.h:76
uint32_t _pad
Definition crypto.h:46
uint32_t infinity
Definition crypto.h:45
LuxScalar256 x
Definition crypto.h:43
LuxScalar256 y
Definition crypto.h:44
uint32_t _pad
Definition crypto.h:61
LuxFp384 y
Definition crypto.h:59
LuxFp384 x
Definition crypto.h:58
uint32_t infinity
Definition crypto.h:60
LuxScalar256 y
Definition crypto.h:52
LuxScalar256 x
Definition crypto.h:51
LuxScalar256 z
Definition crypto.h:53
LuxFp2_381 x
Definition crypto.h:84
uint32_t infinity
Definition crypto.h:86
LuxFp2_381 y
Definition crypto.h:85
uint32_t _pad
Definition crypto.h:87
LuxFp2_381 y
Definition crypto.h:94
LuxFp2_381 x
Definition crypto.h:93
LuxFp2_381 z
Definition crypto.h:95