-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make standalone the security (CT) checker
- Loading branch information
Showing
14 changed files
with
166 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ report.log | |
/jasmin.mlpack | ||
/jasminc | ||
/jazz2tex | ||
/jazzcheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
open Jasmin | ||
open Cmdliner | ||
|
||
type arch = Amd64 | CortexM | ||
|
||
let get_arch_module arch call_conv : (module Arch_full.Arch) = | ||
(module Arch_full.Arch_from_Core_arch | ||
((val match arch with | ||
| Amd64 -> | ||
(module (val CoreArchFactory.core_arch_x86 ~use_lea:false | ||
~use_set0:false call_conv) | ||
: Arch_full.Core_arch) | ||
| CortexM -> | ||
(module CoreArchFactory.Core_arch_ARM | ||
: Arch_full.Core_arch)))) | ||
|
||
let arch = | ||
let alts = [ ("x86-64", Amd64); ("arm-m4", CortexM) ] in | ||
let doc = | ||
Format.asprintf "The target architecture (%s)" (Arg.doc_alts_enum alts) | ||
in | ||
let arch = Arg.enum alts in | ||
Arg.(value & opt arch Amd64 & info [ "arch" ] ~doc) | ||
|
||
let call_conv = | ||
let alts = | ||
[ ("linux", Glob_options.Linux); ("windows", Glob_options.Windows) ] | ||
in | ||
let doc = Format.asprintf "Undocumented (%s)" (Arg.doc_alts_enum alts) in | ||
let call_conv = Arg.enum alts in | ||
Arg.( | ||
value | ||
& opt call_conv Glob_options.Linux | ||
& info [ "call-conv"; "cc" ] ~docv:"OS" ~doc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
open Jasmin | ||
open Cmdliner | ||
|
||
type arch | ||
|
||
val get_arch_module : arch -> Glob_options.call_conv -> (module Arch_full.Arch) | ||
val arch : arch Term.t | ||
val call_conv : Glob_options.call_conv Term.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
open Jasmin | ||
open Cmdliner | ||
open CommonCLI | ||
open Utils | ||
|
||
let parse_and_check arch call_conv = | ||
let module A = (val get_arch_module arch call_conv) in | ||
let check infer ct_list file = | ||
let _env, pprog, _ast = | ||
try Compile.parse_file A.arch_info file with | ||
| Annot.AnnotationError (loc, code) -> | ||
hierror ~loc:(Lone loc) ~kind:"annotation error" "%t" code | ||
| Pretyping.TyError (loc, code) -> | ||
hierror ~loc:(Lone loc) ~kind:"typing error" "%a" Pretyping.pp_tyerror | ||
code | ||
| Syntax.ParseError (loc, msg) -> | ||
hierror ~loc:(Lone loc) ~kind:"parse error" "%s" | ||
(Option.default "" msg) | ||
in | ||
let prog = | ||
try Compile.preprocess A.reg_size A.asmOp pprog | ||
with Typing.TyError (loc, code) -> | ||
hierror ~loc:(Lmore loc) ~kind:"typing error" "%s" code | ||
in | ||
|
||
let sigs, errs = | ||
Ct_checker_forward.ty_prog A.is_ct_sopn ~infer prog ct_list | ||
in | ||
Format.printf "/* Security types:\n@[<v>%a@]*/@." | ||
(pp_list "@ " (Ct_checker_forward.pp_signature prog)) | ||
sigs; | ||
let on_err (loc, msg) = | ||
hierror ~loc:(Lone loc) ~kind:"constant type checker" "%t" msg | ||
in | ||
Stdlib.Option.iter on_err errs | ||
in | ||
fun infer ct_list file -> | ||
match check infer ct_list file with | ||
| () -> () | ||
| exception HiError e -> | ||
Format.eprintf "%a@." pp_hierror e; | ||
exit 1 | ||
|
||
let infer = | ||
let doc = "Infer security contracts" in | ||
Arg.(value & flag & info [ "infer" ] ~doc) | ||
|
||
let slice = | ||
let doc = | ||
"Only check the given function (and its dependencies). This argument may \ | ||
be repeated to check many functions. If not given, all functions will be \ | ||
checked." | ||
in | ||
Arg.(value & opt_all string [] & info [ "slice"; "only"; "on" ] ~doc) | ||
|
||
let file = | ||
let doc = "The Jasmin source file to verify" in | ||
Arg.(required & pos 0 (some non_dir_file) None & info [] ~docv:"JAZZ" ~doc) | ||
|
||
let () = | ||
let doc = "Check Constant-Time security of Jasmin programs" in | ||
let man = | ||
[ | ||
`S Manpage.s_environment; | ||
Manpage.s_environment_intro; | ||
`I ("OCAMLRUNPARAM", "This is an OCaml program"); | ||
`I ("JASMINPATH", "To resolve $(i,require) directives"); | ||
] | ||
in | ||
let info = | ||
Cmd.info "jazzcheck" ~version:Glob_options.version_string ~doc ~man | ||
in | ||
Cmd.v info | ||
Term.(const parse_and_check $ arch $ call_conv $ infer $ slice $ file) | ||
|> Cmd.eval |> exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
set -ex | ||
|
||
exec $(dirname $0)/../jasminc -checkCT "$@" | ||
exec $(dirname $0)/../jazzcheck "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters