Skip to content

Commit

Permalink
core/crypto: Add rodata annotations (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yawning committed Sep 15, 2024
1 parent b3fd77a commit 4e0fa40
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 23 deletions.
1 change: 1 addition & 0 deletions core/crypto/_aes/aes.odin
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ GHASH_BLOCK_SIZE :: 16
GHASH_TAG_SIZE :: 16

// RCON is the AES keyschedule round constants.
@(rodata)
RCON := [10]byte{0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1B, 0x36}
4 changes: 2 additions & 2 deletions core/crypto/_blake2/blake2.odin
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ Blake2_Tree :: struct {
is_last_node: bool,
}

@(private)
@(private, rodata)
BLAKE2S_IV := [8]u32 {
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
}

@(private)
@(private, rodata)
BLAKE2B_IV := [8]u64 {
0x6a09e667f3bcc908, 0xbb67ae8584caa73b,
0x3c6ef372fe94f82b, 0xa54ff53a5f1d36f1,
Expand Down
8 changes: 5 additions & 3 deletions core/crypto/_edwards25519/edwards25519.odin
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,31 @@ import "core:mem"
// - The group element decoding routine takes the opinionated stance of
// rejecting non-canonical encodings.

@(rodata)
FE_D := field.Tight_Field_Element {
929955233495203,
466365720129213,
1662059464998953,
2033849074728123,
1442794654840575,
}
@(private)
@(private, rodata)
FE_A := field.Tight_Field_Element {
2251799813685228,
2251799813685247,
2251799813685247,
2251799813685247,
2251799813685247,
}
@(private)
@(private, rodata)
FE_D2 := field.Tight_Field_Element {
1859910466990425,
932731440258426,
1072319116312658,
1815898335770999,
633789495995903,
}
@(private)
@(private, rodata)
GE_BASEPOINT := Group_Element {
field.Tight_Field_Element {
1738742601995546,
Expand All @@ -79,6 +80,7 @@ GE_BASEPOINT := Group_Element {
1821297809914039,
},
}
@(rodata)
GE_IDENTITY := Group_Element {
field.Tight_Field_Element{0, 0, 0, 0, 0},
field.Tight_Field_Element{1, 0, 0, 0, 0},
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/_edwards25519/edwards25519_scalar.odin
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Scalar :: field.Montgomery_Domain_Field_Element

// WARNING: This is non-canonical and only to be used when checking if
// a group element is on the prime-order subgroup.
@(private)
@(private, rodata)
SC_ELL := field.Non_Montgomery_Domain_Field_Element {
field.ELL[0],
field.ELL[1],
Expand Down
3 changes: 3 additions & 0 deletions core/crypto/_fiat/field_curve25519/field51.odin
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ import "core:math/bits"
Loose_Field_Element :: distinct [5]u64
Tight_Field_Element :: distinct [5]u64

@(rodata)
FE_ZERO := Tight_Field_Element{0, 0, 0, 0, 0}
@(rodata)
FE_ONE := Tight_Field_Element{1, 0, 0, 0, 0}

@(rodata)
FE_SQRT_M1 := Tight_Field_Element {
1718705420411056,
234908883556509,
Expand Down
4 changes: 2 additions & 2 deletions core/crypto/_fiat/field_scalar25519/field.odin
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import "core:encoding/endian"
import "core:math/bits"
import "core:mem"

@(private)
@(private, rodata)
_TWO_168 := Montgomery_Domain_Field_Element {
0x5b8ab432eac74798,
0x38afddd6de59d5d7,
0xa2c131b399411b7c,
0x6329a7ed9ce5a30,
}
@(private)
@(private, rodata)
_TWO_336 := Montgomery_Domain_Field_Element {
0xbd3d108e2b35ecc5,
0x5c3a3718bdf9c90b,
Expand Down
6 changes: 3 additions & 3 deletions core/crypto/_sha3/sha3.odin
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Context :: struct {
is_finalized: bool, // For SHAKE (unlimited squeeze is allowed)
}

@(private)
@(private, rodata)
keccakf_rndc := [?]u64 {
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
Expand All @@ -56,13 +56,13 @@ keccakf_rndc := [?]u64 {
0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
}

@(private)
@(private, rodata)
keccakf_rotc := [?]int {
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44,
}

@(private)
@(private, rodata)
keccakf_piln := [?]i32 {
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1,
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/_sha3/sp800_185.odin
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ rate_cshake :: #force_inline proc(sec_strength: int) -> int {
//
// Thus we support 0 <= x < 2^128.

@(private)
@(private, rodata)
_PAD: [RATE_128]byte // Biggest possible value of w per spec.

bytepad :: proc(ctx: ^Context, x_strings: [][]byte, w: int) {
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/chacha20poly1305/chacha20poly1305.odin
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ _validate_common_slice_sizes :: proc (tag, iv, aad, text: []byte, is_xchacha: bo
}
}

@(private)
@(private, rodata)
_PAD: [16]byte

@(private)
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/kmac/kmac.odin
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ _init_kmac :: proc(ctx: ^Context, key, s: []byte, sec_strength: int) {
_sha3.bytepad(ctx_, [][]byte{key}, _sha3.rate_cshake(sec_strength))
}

@(private)
@(private, rodata)
N_KMAC := []byte{'K', 'M', 'A', 'C'}
10 changes: 5 additions & 5 deletions core/crypto/ristretto255/ristretto255.odin
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,39 @@ ELEMENT_SIZE :: 32
// group element.
WIDE_ELEMENT_SIZE :: 64

@(private)
@(private, rodata)
FE_NEG_ONE := field.Tight_Field_Element {
2251799813685228,
2251799813685247,
2251799813685247,
2251799813685247,
2251799813685247,
}
@(private)
@(private, rodata)
FE_INVSQRT_A_MINUS_D := field.Tight_Field_Element {
278908739862762,
821645201101625,
8113234426968,
1777959178193151,
2118520810568447,
}
@(private)
@(private, rodata)
FE_ONE_MINUS_D_SQ := field.Tight_Field_Element {
1136626929484150,
1998550399581263,
496427632559748,
118527312129759,
45110755273534,
}
@(private)
@(private, rodata)
FE_D_MINUS_ONE_SQUARED := field.Tight_Field_Element {
1507062230895904,
1572317787530805,
683053064812840,
317374165784489,
1572899562415810,
}
@(private)
@(private, rodata)
FE_SQRT_AD_MINUS_ONE := field.Tight_Field_Element {
2241493124984347,
425987919032274,
Expand Down
4 changes: 2 additions & 2 deletions core/crypto/sha2/sha2.odin
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ reset :: proc(ctx: ^$T) {
SHA2 implementation
*/

@(private)
@(private, rodata)
sha256_k := [64]u32 {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
Expand All @@ -290,7 +290,7 @@ sha256_k := [64]u32 {
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
}

@(private)
@(private, rodata)
sha512_k := [80]u64 {
0x428a2f98d728ae22, 0x7137449123ef65cd,
0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc,
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/sm3/sm3.odin
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ reset :: proc(ctx: ^Context) {
SM3 implementation
*/

@(private)
@(private, rodata)
IV := [8]u32 {
0x7380166f, 0x4914b2b9, 0x172442d7, 0xda8a0600,
0xa96f30bc, 0x163138aa, 0xe38dee4d, 0xb0fb0e4e,
Expand Down
2 changes: 1 addition & 1 deletion core/crypto/x25519/x25519.odin
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SCALAR_SIZE :: 32
// POINT_SIZE is the size of a X25519 point (public key/shared secret) in bytes.
POINT_SIZE :: 32

@(private)
@(private, rodata)
_BASE_POINT: [32]byte = {9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

@(private)
Expand Down

0 comments on commit 4e0fa40

Please sign in to comment.