Skip to content

Commit

Permalink
PowerPC integration with initial SHA implementation
Browse files Browse the repository at this point in the history
Hacl integration includes the following features
- Basic vale support of PowerPC architecture.
- Memory layout and heapleat support.
- Stack functionalities (alloc, dealloc, store, load..)
- QuickCode support.
- Add more basic and vector instructions that utilized in SHA implementation.
- Expand lemmas of which have use cases.
  • Loading branch information
mamonet committed Aug 4, 2022
1 parent 0a58b63 commit 46e7e73
Show file tree
Hide file tree
Showing 41 changed files with 9,185 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ ifndef MAKE_RESTARTS
$(call run-with-log,\
$(FSTAR_NO_FLAGS) --dep $* $(notdir $(FSTAR_ROOTS)) --warn_error '-285' $(FSTAR_DEPEND_FLAGS) \
--extract 'krml:*' \
--extract 'OCaml:-* +FStar.Krml.Endianness +Vale.Arch +Vale.X64 -Vale.X64.MemoryAdapters +Vale.Def +Vale.Lib +Vale.Bignum.X64 -Vale.Lib.Tactics +Vale.Math +Vale.Transformers +Vale.AES +Vale.Interop +Vale.Arch.Types +Vale.Arch.BufferFriend +Vale.Lib.X64 +Vale.SHA.X64 +Vale.SHA.SHA_helpers +Vale.Curve25519.X64 +Vale.Poly1305.X64 +Vale.Inline +Vale.AsLowStar +Vale.Test +Spec +Lib -Lib.IntVector -Lib.Memzero0 -Lib.Buffer -Lib.MultiBuffer +C -C.String -C.Failure' > $@ && \
--extract 'OCaml:-* +FStar.Krml.Endianness +Vale.Arch +Vale.X64 -Vale.X64.MemoryAdapters +Vale.Def +Vale.Lib +Vale.Bignum.X64 -Vale.Lib.Tactics +Vale.Math +Vale.Transformers +Vale.AES +Vale.Interop +Vale.Arch.Types +Vale.Arch.BufferFriend +Vale.Lib.X64 +Vale.SHA.X64 +Vale.SHA.SHA_helpers +Vale.PPC64LE +Vale.SHA2.Wrapper +Vale.SHA.PPC64LE +Vale.Curve25519.X64 +Vale.Poly1305.X64 +Vale.Inline +Vale.AsLowStar +Vale.Test +Spec +Lib -Lib.IntVector -Lib.Memzero0 -Lib.Buffer -Lib.MultiBuffer +C -C.String -C.Failure' > $@ && \
$(SED) 's!$(HACL_HOME)/obj/\(.*.checked\)!obj/\1!;s!/bin/../ulib/!/ulib/!g' $@ \
,[FSTAR-DEPEND ($*)],$(call to-obj-dir,$@))

Expand Down Expand Up @@ -528,6 +528,7 @@ dist/vale/%-inline.h: obj/inline-vale-%.exe | dist/vale
obj/vale-cpuid.exe: vale/code/lib/util/x64/CpuidMain.ml
obj/vale-aesgcm.exe: vale/code/crypto/aes/x64/Main.ml
obj/vale-sha256.exe: vale/code/crypto/sha/ShaMain.ml
obj/vale-sha256-ppc.exe: vale/code/crypto/sha/ShaMainPPC64LE.ml
obj/vale-curve25519.exe: vale/code/crypto/ecc/curve25519/Main25519.ml
obj/vale-poly1305.exe: vale/code/crypto/poly1305/x64/PolyMain.ml

Expand Down
1 change: 1 addition & 0 deletions Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ VALE_DIRS = \
$(HACL_HOME)/vale/code/arch \
$(HACL_HOME)/vale/code/arch/x64 \
$(HACL_HOME)/vale/code/arch/x64/interop \
$(HACL_HOME)/vale/code/arch/ppc64le \
$(HACL_HOME)/vale/code/crypto/aes \
$(HACL_HOME)/vale/code/crypto/aes/x64 \
$(HACL_HOME)/vale/code/crypto/bignum \
Expand Down
2 changes: 1 addition & 1 deletion Makefile.local
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ifndef MAKE_RESTARTS
.depend: .FORCE
$(FSTAR_NO_FLAGS) --dep full $(notdir $(FSTAR_ROOTS)) \
--extract 'krml:*' \
--extract 'OCaml:-* +FStar.Krml.Endianness +Vale.Arch +Vale.X64 -Vale.X64.MemoryAdapters +Vale.Def +Vale.Lib +Vale.Bignum.X64 -Vale.Lib.Tactics +Vale.Math +Vale.Transformers +Vale.AES +Vale.Interop +Vale.Arch.Types +Vale.Arch.BufferFriend +Vale.Lib.X64 +Vale.SHA.X64 +Vale.SHA.SHA_helpers +Vale.Curve25519.X64 +Vale.Poly1305.X64 +Vale.Inline +Vale.AsLowStar +Vale.Test +Spec +Lib -Lib.IntVector +C' \
--extract 'OCaml:-* +FStar.Krml.Endianness +Vale.Arch +Vale.X64 -Vale.X64.MemoryAdapters +Vale.Def +Vale.Lib +Vale.Bignum.X64 -Vale.Lib.Tactics +Vale.Math +Vale.Transformers +Vale.AES +Vale.Interop +Vale.Arch.Types +Vale.Arch.BufferFriend +Vale.Lib.X64 +Vale.SHA.X64 +Vale.SHA.SHA_helpers +Vale.PPC64LE +Vale.SHA2.Wrapper +Vale.SHA.PPC64LE +Vale.Curve25519.X64 +Vale.Poly1305.X64 +Vale.Inline +Vale.AsLowStar +Vale.Test +Spec +Lib -Lib.IntVector +C' \
> $@

.PHONY: .FORCE
Expand Down
100 changes: 100 additions & 0 deletions vale/code/arch/ppc64le/Vale.PPC64LE.Decls.fst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
module Vale.PPC64LE.Decls
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.State
open Vale.PPC64LE.StateLemmas
module S = Vale.PPC64LE.Semantics_s
module P = Vale.PPC64LE.Print_s
friend Vale.PPC64LE.Memory

let same_heap_types = ()

let xer_ov = Lemmas.xer_ov
let xer_ca = Lemmas.xer_ca
let update_xer_ov = Lemmas.update_xer_ov
let update_xer_ca = Lemmas.update_xer_ca
let ins = S.ins
type ocmp = S.ocmp
type va_fuel = nat

type va_pbool = Vale.Def.PossiblyMonad.pbool
let va_ttrue () = Vale.Def.PossiblyMonad.ttrue
let va_ffalse = Vale.Def.PossiblyMonad.ffalse
let va_pbool_and x y = Vale.Def.PossiblyMonad.((&&.)) x y

let mul_nat_helper x y =
FStar.Math.Lemmas.nat_times_nat_is_nat x y

let va_fuel_default () = 0

let lemma_opr_Mem64 (id:heaplet_id) (s:va_state) (address:reg_opr) (offset:int) (b:M.buffer64) (index:int) (t:taint) : Lemma
(requires (
let h = Map16.sel s.ms_heap.vf_heaplets id in
M.mem_inv (coerce s.ms_heap) /\
valid_src_addr h b index /\
M.valid_layout_buffer b (s.ms_heap.vf_layout) h false /\
M.valid_taint_buf64 b h (full_heap_taint s.ms_heap) t /\
eval_reg address s + offset == M.buffer_addr b h + 8 * index
))
(ensures (
let h = Map16.sel s.ms_heap.vf_heaplets id in
valid_mem_addr (va_opr_code_Mem64 id address offset t) s /\
M.load_mem64 (M.buffer_addr b h + 8 * index) (s.ms_heap.vf_heap) == M.buffer_read b index h
))
=
Vale.PPC64LE.Memory_Sems.low_lemma_load_mem64_full b index s.ms_heap t id;
let h = M.get_vale_heap s.ms_heap in
let t = va_opr_code_Mem64 id address offset t in
M.lemma_valid_mem64 b index h;
let (m, t) = t in
assert (valid_buf_maddr64 (eval_maddr m s) h s.ms_heap.vf_layout b index t);
M.lemma_load_mem64 b index h

let va_cmp_eq o1 o2 = S.OEq o1 o2
let va_cmp_ne o1 o2 = S.ONe o1 o2
let va_cmp_le o1 o2 = S.OLe o1 o2
let va_cmp_ge o1 o2 = S.OGe o1 o2
let va_cmp_lt o1 o2 = S.OLt o1 o2
let va_cmp_gt o1 o2 = S.OGt o1 o2

let eval_code = Lemmas.eval_code
let eval_while_inv = Lemmas.eval_while_inv

let va_ins_lemma c0 s0 = ()

let eval_ocmp = Lemmas.eval_ocmp
let valid_ocmp = Lemmas.valid_ocmp
let eval_cmp_cr0 = S.eval_cmp_cr0

unfold let va_eval_ins = Lemmas.eval_ins

let lemma_cmp_eq s o1 o2 = ()
let lemma_cmp_ne s o1 o2 = ()
let lemma_cmp_le s o1 o2 = ()
let lemma_cmp_ge s o1 o2 = ()
let lemma_cmp_lt s o1 o2 = ()
let lemma_cmp_gt s o1 o2 = ()

let lemma_valid_cmp_eq s o1 o2 = ()
let lemma_valid_cmp_ne s o1 o2 = ()
let lemma_valid_cmp_le s o1 o2 = ()
let lemma_valid_cmp_ge s o1 o2 = ()
let lemma_valid_cmp_lt s o1 o2 = ()
let lemma_valid_cmp_gt s o1 o2 = ()

let va_compute_merge_total = Lemmas.compute_merge_total
let va_lemma_merge_total b0 s0 f0 sM fM sN = Lemmas.lemma_merge_total b0 s0 f0 sM fM sN; Lemmas.compute_merge_total f0 fM
let va_lemma_empty_total = Lemmas.lemma_empty_total
let va_lemma_ifElse_total = Lemmas.lemma_ifElse_total
let va_lemma_ifElseTrue_total = Lemmas.lemma_ifElseTrue_total
let va_lemma_ifElseFalse_total = Lemmas.lemma_ifElseFalse_total
let va_lemma_while_total = Lemmas.lemma_while_total
let va_lemma_whileTrue_total = Lemmas.lemma_whileTrue_total
let va_lemma_whileFalse_total = Lemmas.lemma_whileFalse_total
let va_lemma_whileMerge_total = Lemmas.lemma_whileMerge_total

let printer = P.printer
let print_string = FStar.IO.print_string
let print_header = P.print_header
let print_proc = P.print_proc
let print_footer = P.print_footer
let gcc = P.gcc
Loading

0 comments on commit 46e7e73

Please sign in to comment.