-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trusted boot: firmware.c specifications pass (#123)
- Loading branch information
1 parent
0a113bf
commit d255dc0
Showing
9 changed files
with
308 additions
and
43 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
120 changes: 120 additions & 0 deletions
120
components/platform_crypto/shave_trusted_boot/cn_array_utils.h
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,120 @@ | ||
#ifndef CN_ARRAY_UTILS_H_ | ||
#define CN_ARRAY_UTILS_H_ | ||
|
||
/*$ | ||
predicate (map<u64,u8>) ArrayOrNull_u8 (pointer p, u64 l) | ||
{ | ||
if (!is_null(p)) { | ||
take pv = each(u64 i; i >= 0u64 && i < l) {Owned<uint8_t>(array_shift<uint8_t>(p,i))}; | ||
return pv; | ||
} else { | ||
return default<map<u64,u8> >; | ||
} | ||
} | ||
lemma SplitAt_Block_u8(pointer tmp, u64 len, u64 at, u64 slen) | ||
requires | ||
take a1 = each(u64 j; 0u64<=j && j<len){Block<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
at >= 0u64; | ||
len >= 0u64; | ||
slen >= 0u64; | ||
at < len; | ||
slen <= len; | ||
at + slen <= len; | ||
ensures | ||
take a2 = each(u64 j; 0u64<=j && j<at){Block<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
take a3 = each(u64 j; ((u64)at)<=j && j<(at+slen)){Block<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
take a4 = each(u64 j; ((u64)(at+slen))<=j && j<len){Block<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
lemma SplitAt_Owned_u8(pointer tmp, u64 len, u64 at, u64 slen) | ||
requires | ||
take a1 = each(u64 j; 0u64<=j && j<len){Owned<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
at >= 0u64; | ||
len >= 0u64; | ||
slen >= 0u64; | ||
at < len; | ||
slen <= len; | ||
at + slen <= len; | ||
ensures | ||
take a2 = each(u64 j; 0u64<=j && j<at){Owned<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
take a3 = each(u64 j; ((u64)at)<=j && j<(at+slen)){Owned<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
take a4 = each(u64 j; ((u64)(at+slen))<=j && j<len){Owned<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
lemma UnsplitAt_Block_u8(pointer tmp, u64 len, u64 at, u64 slen) | ||
requires | ||
take a2 = each(u64 j; 0u64<=j && j<at){Block<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
take a3 = each(u64 j; ((u64)at)<=j && j<(at+slen)){Block<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
take a4 = each(u64 j; ((u64)(at+slen))<=j && j<len){Block<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
at >= 0u64; | ||
len >= 0u64; | ||
slen >= 0u64; | ||
at < len; | ||
slen <= len; | ||
at + slen <= len; | ||
ensures | ||
take a1 = each(u64 j; 0u64<=j && j<len){Block<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
lemma UnSplitAt_Owned_u8(pointer tmp, u64 len, u64 at, u64 slen) | ||
requires | ||
take a2 = each(u64 j; 0u64<=j && j<at){Owned<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
take a3 = each(u64 j; ((u64)at)<=j && j<(at+slen)){Owned<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
take a4 = each(u64 j; ((u64)(at+slen))<=j && j<len){Owned<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
at >= 0u64; | ||
len >= 0u64; | ||
slen >= 0u64; | ||
at < len; | ||
slen <= len; | ||
at + slen <= len; | ||
ensures | ||
take a1 = each(u64 j; 0u64<=j && j<len){Owned<uint8_t>(array_shift<uint8_t>(tmp, j))}; | ||
lemma ViewShift_Block_u8(pointer a, pointer b, u64 at, u64 len) | ||
requires | ||
take a1 = each(u64 j; at <= j && j <(at+len)) {Block<uint8_t>(array_shift<uint8_t>(a,j))}; | ||
ptr_eq(array_shift<uint8_t>(b,0u64), array_shift<uint8_t>(a,at)); | ||
ensures | ||
take a2 = each(u64 j; 0u64 <= j && j <len) {Block<uint8_t>(array_shift<uint8_t>(b,j))}; | ||
lemma ViewShift_Owned_u8(pointer a, pointer b, u64 at, u64 len) | ||
requires | ||
take a1 = each(u64 j; at <= j && j <(at+len)) {Owned<uint8_t>(array_shift<uint8_t>(a,j))}; | ||
ptr_eq(array_shift<uint8_t>(b,0u64), array_shift<uint8_t>(a,at)); | ||
ensures | ||
take a2 = each(u64 j; 0u64 <= j && j <len) {Owned<uint8_t>(array_shift<uint8_t>(b,j))}; | ||
lemma UnViewShift_Block_u8(pointer a, pointer b, u64 at, u64 len) | ||
requires | ||
take a2 = each(u64 j; 0u64 <= j && j <len) {Block<uint8_t>(array_shift<uint8_t>(b,j))}; | ||
ptr_eq(array_shift<uint8_t>(b,0u64), array_shift<uint8_t>(a,at)); | ||
ensures | ||
take a1 = each(u64 j; at <= j && j <(at+len)) {Block<uint8_t>(array_shift<uint8_t>(a,j))}; | ||
lemma UnViewShift_Owned_u8(pointer a, pointer b, u64 at, u64 len) | ||
requires | ||
take a2 = each(u64 j; 0u64 <= j && j <len) {Owned<uint8_t>(array_shift<uint8_t>(b,j))}; | ||
ptr_eq(array_shift<uint8_t>(b,0u64), array_shift<uint8_t>(a,at)); | ||
ensures | ||
take a1 = each(u64 j; at <= j && j <(at+len)) {Owned<uint8_t>(array_shift<uint8_t>(a,j))}; | ||
predicate (map<u64,u8>) CondArraySliceBlock_u8 (pointer p, boolean c, u64 s, u64 e) | ||
{ | ||
if (c) { | ||
take pv = each(u64 i; i >= s && i < e) {Block<uint8_t>(array_shift<uint8_t>(p,i))}; | ||
return pv; | ||
} else { | ||
return default<map<u64,u8> >; | ||
} | ||
} | ||
predicate (map<u64,u8>) CondArraySliceOwned_u8 (pointer p, boolean c, u64 s, u64 e) | ||
{ | ||
if (c) { | ||
take pv = each(u64 i; i >= s && i < e) {Owned<uint8_t>(array_shift<uint8_t>(p,i))}; | ||
return pv; | ||
} else { | ||
return default<map<u64,u8> >; | ||
} | ||
} | ||
$*/ | ||
|
||
#endif // CN_ARRAY_UTILS_H_ |
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,33 @@ | ||
#ifndef CN_MEMCPY_H_ | ||
#define CN_MEMCPY_H_ | ||
|
||
int _memcmp(const unsigned char *dest, const unsigned char *src, size_t n); | ||
/*$ spec _memcmp(pointer dest, pointer src, u64 n); | ||
requires | ||
take Src = each (u64 i; 0u64 <= i && i < n ) { Owned(array_shift(src, i)) }; | ||
take Dest = each (u64 i; 0u64 <= i && i < n ) { Owned(array_shift(dest, i)) }; | ||
ensures | ||
take SrcR = each (u64 i; 0u64 <= i && i < n ) { Owned(array_shift(src, i)) }; | ||
take DestR = each (u64 i; 0u64 <= i && i < n ) { Owned(array_shift(dest, i)) }; | ||
Src == SrcR; Dest == DestR; | ||
(return != 0i32 || Src == Dest) && (return == 0i32 || Src != Dest); | ||
$*/ | ||
|
||
void _memcpy(unsigned char *dest, | ||
const unsigned char *src, size_t n); | ||
/*$ | ||
spec _memcpy(pointer dest, pointer src, u64 n); | ||
requires | ||
take Src = each (u64 i; 0u64 <= i && i < n ) { Owned(array_shift(src, i)) }; | ||
take Dest = each (u64 i; 0u64 <= i && i < n ) { Block<unsigned char>(array_shift(dest, i)) }; | ||
ensures | ||
take SrcR = each (u64 i; 0u64 <= i && i < n ) { Owned(array_shift(src, i)) }; | ||
take DestR = each (u64 i; 0u64 <= i && i < n ) { Owned(array_shift(dest, i)) }; | ||
Src == SrcR; | ||
each (u64 i; 0u64 <= i && i < n ) { SrcR[i] == DestR[i] }; | ||
$*/ | ||
|
||
#endif // CN_MEMCPY_H_ |
Oops, something went wrong.