mirror of
https://github.com/odin-lang/Odin.git
synced 2026-05-29 15:15:08 +00:00
core/crypto/mlkem: Minor cleanups
This commit is contained in:
@@ -58,7 +58,7 @@ poly_compress :: proc "contextless" (r: []byte, a: ^Poly) #no_bounds_check {
|
||||
r = r[5:]
|
||||
}
|
||||
case:
|
||||
panic_contextless("crypto/mlkem: invalid POLYCOMPRESSEDBYTES")
|
||||
unreachable()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ poly_decompress :: proc "contextless" (r: ^Poly, a: []byte) {
|
||||
}
|
||||
}
|
||||
case:
|
||||
panic_contextless("crypto/mlkem: invalid POLYCOMPRESSEDBYTES")
|
||||
unreachable()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,6 +236,6 @@ poly_compressed_bytes :: #force_inline proc "contextless" (k: int) -> int {
|
||||
case K_1024:
|
||||
return POLYCOMPRESSEDBYTES_1024
|
||||
case:
|
||||
panic_contextless("crypto/mlkem: invalid k")
|
||||
unreachable()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ polyvec_compress :: proc "contextless" (r: []byte, a: ^Polyvec, kay: int) #no_bo
|
||||
}
|
||||
}
|
||||
case:
|
||||
panic_contextless("crypto/mlkem: invalid POLYVECCOMPRESSEDBYTES")
|
||||
unreachable()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ polyvec_decompress :: proc "contextless" (r: ^Polyvec, a: []byte, kay: int) #no_
|
||||
}
|
||||
}
|
||||
case:
|
||||
panic_contextless("crypto/mlkem: invalid POLYVECCOMPRESSEDBYTES")
|
||||
unreachable()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -253,6 +253,28 @@ decaps :: proc(dk: ^Decapsulation_Key, ciphertext, shared_secret: []byte) -> boo
|
||||
return true
|
||||
}
|
||||
|
||||
// params returns the Parameters used by a Decapsulation_Key or
|
||||
// Encapsulation_Key instance.
|
||||
@(require_results)
|
||||
params :: proc(k: ^$T) -> Parameters where (T == Encapsulation_Key || T == Decapsulation_Key) {
|
||||
when T == Encapsulation_Key {
|
||||
return k_to_params(k.pke_ek.k)
|
||||
} else {
|
||||
return k_to_params(k.pke_dk.k)
|
||||
}
|
||||
}
|
||||
|
||||
// key_size returns the key size of a Decapsulation_Key or Encapsulation_Key
|
||||
// in bytes.
|
||||
@(require_results)
|
||||
key_size :: proc(k: ^$T) -> int where (T == Encapsulation_Key || T == Decapsulation_Key) {
|
||||
when T == Encapsulation_Key {
|
||||
return ENCAPSULATION_KEY_SIZES[k.pke_ek.k]
|
||||
} else {
|
||||
return DECAPSULATION_KEY_SEED_SIZE
|
||||
}
|
||||
}
|
||||
|
||||
@(private="file")
|
||||
params_to_k :: #force_inline proc "contextless" (params: Parameters) -> int {
|
||||
#partial switch params {
|
||||
@@ -266,3 +288,17 @@ params_to_k :: #force_inline proc "contextless" (params: Parameters) -> int {
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@(private="file")
|
||||
k_to_params :: #force_inline proc "contextless" (k: int) -> Parameters {
|
||||
switch k {
|
||||
case _mlkem.K_512:
|
||||
return .ML_KEM_512
|
||||
case _mlkem.K_768:
|
||||
return .ML_KEM_768
|
||||
case _mlkem.K_1024:
|
||||
return .ML_KEM_1024
|
||||
}
|
||||
|
||||
return .Invalid
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user