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
17
extern
"C"
{
18
#endif
19
20
// =============================================================================
21
// Field Types
22
// =============================================================================
23
24
// 256-bit scalar (BN254 base/scalar, BLS12-381 scalar, secp256k1, ed25519)
25
typedef
struct
{
26
uint64_t limbs[4];
27
}
LuxScalar256
;
28
29
// 384-bit base field element (BLS12-381)
30
typedef
struct
{
31
uint64_t limbs[6];
32
}
LuxFp384
;
33
34
// 64-bit Goldilocks field element (2^64 - 2^32 + 1)
35
typedef
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
42
typedef
struct
{
43
LuxScalar256
x
;
44
LuxScalar256
y
;
45
uint32_t
infinity
;
46
uint32_t
_pad
;
47
}
LuxG1Affine254
;
48
49
// G1 projective (Jacobian) point (BN254)
50
typedef
struct
{
51
LuxScalar256
x
;
52
LuxScalar256
y
;
53
LuxScalar256
z
;
54
}
LuxG1Projective254
;
55
56
// G1 affine point (BLS12-381) — Fp384 is 6×u64
57
typedef
struct
{
58
LuxFp384
x
;
59
LuxFp384
y
;
60
uint32_t
infinity
;
61
uint32_t
_pad
;
62
}
LuxG1Affine381
;
63
64
// G1 projective (Jacobian) point (BLS12-381)
65
typedef
struct
{
66
LuxFp384
x
;
67
LuxFp384
y
;
68
LuxFp384
z
;
69
}
LuxG1Projective381
;
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.
75
typedef
struct
{
76
LuxFp384
c0
;
77
LuxFp384
c1
;
78
}
LuxFp2_381
;
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.
83
typedef
struct
{
84
LuxFp2_381
x
;
85
LuxFp2_381
y
;
86
uint32_t
infinity
;
87
uint32_t
_pad
;
88
}
LuxG2Affine381
;
89
90
// G2 projective (Jacobian) point. Layout matches blst's
91
// `blst_p2 { blst_fp2 x, y, z; }`.
92
typedef
struct
{
93
LuxFp2_381
x
;
94
LuxFp2_381
y
;
95
LuxFp2_381
z
;
96
}
LuxG2Projective381
;
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).
101
typedef
struct
{
102
LuxFp2_381
fp2[6];
103
}
LuxFp12_381
;
104
105
// =============================================================================
106
// Error Codes
107
// =============================================================================
108
109
typedef
enum
{
110
LUX_CRYPTO_OK
= 0,
111
LUX_CRYPTO_ERROR_INVALID_ARG
= 1,
112
LUX_CRYPTO_ERROR_OUT_OF_MEMORY
= 2,
113
LUX_CRYPTO_ERROR_NOT_SUPPORTED
= 3,
114
LUX_CRYPTO_ERROR_INVALID_CURVE
= 4,
115
LUX_CRYPTO_ERROR_INVALID_POINT
= 5,
116
LUX_CRYPTO_ERROR_DEVICE_ERROR
= 6,
117
}
LuxCryptoError
;
118
119
#ifdef __cplusplus
120
}
121
#endif
122
123
#endif
// LUX_GPU_CRYPTO_H
LuxGoldilocks
uint64_t LuxGoldilocks
Definition
crypto.h:35
LuxCryptoError
LuxCryptoError
Definition
crypto.h:109
LUX_CRYPTO_ERROR_INVALID_CURVE
@ LUX_CRYPTO_ERROR_INVALID_CURVE
Definition
crypto.h:114
LUX_CRYPTO_ERROR_OUT_OF_MEMORY
@ LUX_CRYPTO_ERROR_OUT_OF_MEMORY
Definition
crypto.h:112
LUX_CRYPTO_ERROR_INVALID_ARG
@ LUX_CRYPTO_ERROR_INVALID_ARG
Definition
crypto.h:111
LUX_CRYPTO_OK
@ LUX_CRYPTO_OK
Definition
crypto.h:110
LUX_CRYPTO_ERROR_NOT_SUPPORTED
@ LUX_CRYPTO_ERROR_NOT_SUPPORTED
Definition
crypto.h:113
LUX_CRYPTO_ERROR_INVALID_POINT
@ LUX_CRYPTO_ERROR_INVALID_POINT
Definition
crypto.h:115
LUX_CRYPTO_ERROR_DEVICE_ERROR
@ LUX_CRYPTO_ERROR_DEVICE_ERROR
Definition
crypto.h:116
LuxFp12_381
Definition
crypto.h:101
LuxFp2_381
Definition
crypto.h:75
LuxFp2_381::c1
LuxFp384 c1
Definition
crypto.h:77
LuxFp2_381::c0
LuxFp384 c0
Definition
crypto.h:76
LuxFp384
Definition
crypto.h:30
LuxG1Affine254
Definition
crypto.h:42
LuxG1Affine254::_pad
uint32_t _pad
Definition
crypto.h:46
LuxG1Affine254::infinity
uint32_t infinity
Definition
crypto.h:45
LuxG1Affine254::x
LuxScalar256 x
Definition
crypto.h:43
LuxG1Affine254::y
LuxScalar256 y
Definition
crypto.h:44
LuxG1Affine381
Definition
crypto.h:57
LuxG1Affine381::_pad
uint32_t _pad
Definition
crypto.h:61
LuxG1Affine381::y
LuxFp384 y
Definition
crypto.h:59
LuxG1Affine381::x
LuxFp384 x
Definition
crypto.h:58
LuxG1Affine381::infinity
uint32_t infinity
Definition
crypto.h:60
LuxG1Projective254
Definition
crypto.h:50
LuxG1Projective254::y
LuxScalar256 y
Definition
crypto.h:52
LuxG1Projective254::x
LuxScalar256 x
Definition
crypto.h:51
LuxG1Projective254::z
LuxScalar256 z
Definition
crypto.h:53
LuxG1Projective381
Definition
crypto.h:65
LuxG1Projective381::x
LuxFp384 x
Definition
crypto.h:66
LuxG1Projective381::z
LuxFp384 z
Definition
crypto.h:68
LuxG1Projective381::y
LuxFp384 y
Definition
crypto.h:67
LuxG2Affine381
Definition
crypto.h:83
LuxG2Affine381::x
LuxFp2_381 x
Definition
crypto.h:84
LuxG2Affine381::infinity
uint32_t infinity
Definition
crypto.h:86
LuxG2Affine381::y
LuxFp2_381 y
Definition
crypto.h:85
LuxG2Affine381::_pad
uint32_t _pad
Definition
crypto.h:87
LuxG2Projective381
Definition
crypto.h:92
LuxG2Projective381::y
LuxFp2_381 y
Definition
crypto.h:94
LuxG2Projective381::x
LuxFp2_381 x
Definition
crypto.h:93
LuxG2Projective381::z
LuxFp2_381 z
Definition
crypto.h:95
LuxScalar256
Definition
crypto.h:25
lux
gpu
crypto.h
Generated by
1.9.8