upstream: https://github.com/mirage/mirage-crypto
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Clean up debug files, update serialization libraries

Remove ocaml-rice/test/debug/ (temporary libaec debug stubs).
Update ocaml-crypto, ocaml-csvt, ocaml-sexpt, ocaml-tomlt, ocaml-xmlt.

+38 -38
+7 -1
src/c/entropy_cpu_stubs.c
··· 109 109 } 110 110 } 111 111 struct timespec now; 112 + #ifdef CLOCK_MONOTONIC_RAW 113 + clock_gettime (CLOCK_MONOTONIC_RAW, &now); 114 + #else 112 115 clock_gettime (CLOCK_MONOTONIC, &now); 113 - return now.tv_nsec; 116 + #endif 117 + return (uint32_t)now.tv_nsec ^ (uint32_t)now.tv_sec; 114 118 } 115 119 #endif /* __ocaml_freestanding__ || __ocaml_solo5__ */ 116 120 #endif /* arm */ ··· 238 242 int ok = 0; 239 243 int i = 100; 240 244 do { ok = _rdseed_step (&r); _mm_pause (); } while ( !(ok | !--i) ); 245 + ok = ok && (r != 0) && (r != (random_t)(-1)); 241 246 fill_bytes(buf, sizeof(r), off, &r); 242 247 return Val_bool (ok); 243 248 #else ··· 254 259 int ok = 0; 255 260 int i = 10; 256 261 do { ok = _rdrand_step (&r); } while ( !(ok | !--i) ); 262 + ok = ok && (r != 0) && (r != (random_t)(-1)); 257 263 fill_bytes(buf, sizeof(r), off, &r); 258 264 return Val_bool (ok); 259 265 #else
+2
src/crypto.ml
··· 1 + exception Unsupported of string 2 + 1 3 module Uncommon = Uncommon 2 4 module Poly1305 = Poly1305.It 3 5
+4
src/crypto.mli
··· 1 + exception Unsupported of string 2 + (** Raised by backend operations that are not available in the current 3 + implementation (e.g. DES, ChaCha20, Poly1305 in the pure OCaml backend). *) 4 + 1 5 (** Simpler crypto 2 6 3 7 Mirage-crypto is a cryptographic library.
+25 -37
src/ocaml/native.ml
··· 27 27 (* For GCM we only need encrypt direction. Store encryption keys. *) 28 28 derive_e key rk rounds 29 29 30 - (* Cache: avoid re-parsing round keys on every block encrypt *) 31 - let cached_rk = ref "" 32 - let cached_rka = ref [||] 33 - 34 - let get_rka rk rounds = 35 - if rk == !cached_rk then !cached_rka 36 - else 37 - let nrk = (rounds + 1) * 4 in 38 - let rka = 39 - Array.init nrk (fun i -> 40 - let o = i * 4 in 41 - Int32.logor 42 - (Int32.logor 43 - (Int32.shift_left 44 - (Int32.of_int (Char.code (String.get rk o))) 45 - 24) 46 - (Int32.shift_left 47 - (Int32.of_int (Char.code (String.get rk (o + 1)))) 48 - 16)) 49 - (Int32.logor 50 - (Int32.shift_left 51 - (Int32.of_int (Char.code (String.get rk (o + 2)))) 52 - 8) 53 - (Int32.of_int (Char.code (String.get rk (o + 3)))))) 54 - in 55 - cached_rk := rk; 56 - cached_rka := rka; 57 - rka 30 + let parse_rk rk rounds = 31 + let nrk = (rounds + 1) * 4 in 32 + Array.init nrk (fun i -> 33 + let o = i * 4 in 34 + Int32.logor 35 + (Int32.logor 36 + (Int32.shift_left (Int32.of_int (Char.code (String.get rk o))) 24) 37 + (Int32.shift_left 38 + (Int32.of_int (Char.code (String.get rk (o + 1)))) 39 + 16)) 40 + (Int32.logor 41 + (Int32.shift_left 42 + (Int32.of_int (Char.code (String.get rk (o + 2)))) 43 + 8) 44 + (Int32.of_int (Char.code (String.get rk (o + 3)))))) 58 45 59 46 let enc src soff dst doff rk rounds blocks = 60 - let rka = get_rka rk rounds in 47 + let rka = parse_rk rk rounds in 61 48 Aes_pure.encrypt_ecb rka rounds src soff dst doff blocks 62 49 63 50 let dec _src _soff _dst _doff _rk _rounds _blocks = 64 - failwith 65 - "AES decrypt not implemented in pure OCaml backend (GCM uses encrypt \ 66 - only)" 51 + raise 52 + (Crypto.Unsupported 53 + "AES decrypt not available in pure OCaml backend (GCM uses encrypt \ 54 + only)") 67 55 68 56 let mode () = 0 (* generic *) 69 57 end ··· 72 60 let k_s () = 128 73 61 74 62 let des3key _key _mode _ks = 75 - failwith "DES not implemented in pure OCaml backend" 63 + raise (Crypto.Unsupported "DES not available in pure OCaml backend") 76 64 77 65 let ddes _src _soff _dst _doff _blocks _ks = 78 - failwith "DES not implemented in pure OCaml backend" 66 + raise (Crypto.Unsupported "DES not available in pure OCaml backend") 79 67 end 80 68 81 69 module Chacha = struct 82 70 let round _count _state _dst _off = 83 - failwith "ChaCha20 not implemented in pure OCaml backend" 71 + raise (Crypto.Unsupported "ChaCha20 not available in pure OCaml backend") 84 72 end 85 73 86 74 module Poly1305 = struct ··· 89 77 let init _ctx _key = failwith "Poly1305 not implemented in pure OCaml backend" 90 78 91 79 let update _ctx _data _off _len = 92 - failwith "Poly1305 not implemented in pure OCaml backend" 80 + raise (Crypto.Unsupported "Poly1305 not available in pure OCaml backend") 93 81 94 82 let finalize _ctx _mac _off = 95 - failwith "Poly1305 not implemented in pure OCaml backend" 83 + raise (Crypto.Unsupported "Poly1305 not available in pure OCaml backend") 96 84 end 97 85 98 86 module GHASH = struct