-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1
- Loading branch information
Showing
13 changed files
with
505 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
ct: no | ||
--- | ||
|
||
```c | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
typedef uint8_t(* issue_t)(const uint32_t, const uint8_t, const uint8_t); | ||
|
||
uint8_t issue(const uint32_t c, const uint8_t a, const uint8_t b) { | ||
if(c) { | ||
return a; | ||
} | ||
else { | ||
return b; | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
uint32_t a = 2, b = 5, c = 0; | ||
// c is our secret value, we read its content from the environment so the | ||
// compiler cannot play tricks on us by inlining | ||
if (argc >= 2) { | ||
c = (uint32_t) strtol(argv[1], NULL, 16); | ||
} | ||
else { | ||
fprintf(stderr, "USAGE: %s hex_value\n", argv[0]); | ||
return 1; | ||
} | ||
// declarations and markup here | ||
|
||
volatile issue_t func = issue; | ||
printf("%d\n", func(c, a, b)); | ||
|
||
return 0; | ||
} | ||
``` |
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,35 @@ | ||
--- | ||
ct: yes | ||
--- | ||
|
||
```c | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
typedef uint8_t(* issue_t)(const uint32_t, const uint8_t, const uint8_t); | ||
|
||
uint8_t issue(const uint32_t c, const uint8_t a, const uint8_t b) { | ||
int d = !!c; | ||
return d*a + (1-d)*b; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
uint32_t a = 2, b = 5, c = 0; | ||
// c is our secret value, we read its content from the environment so the | ||
// compiler cannot play tricks on us by inlining | ||
if (argc >= 2) { | ||
c = (uint32_t) strtol(argv[1], NULL, 16); | ||
} | ||
else { | ||
fprintf(stderr, "USAGE: %s hex_value\n", argv[0]); | ||
return 1; | ||
} | ||
// declarations and markup here | ||
|
||
volatile issue_t func = issue; | ||
printf("%d", func(c, a, b)); | ||
|
||
return 0; | ||
} | ||
``` |
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,36 @@ | ||
--- | ||
ct: no | ||
--- | ||
|
||
```c | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
typedef uint8_t(* issue_t)(const uint8_t *, const uint8_t *); | ||
|
||
uint8_t issue(const uint8_t *a, const uint8_t *b) { | ||
return a[b[0]]; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
uint8_t a[2] ={2, 5}, b[2] = {0}; | ||
// b is our secret value containing array, we read its content from the | ||
// environment so the compiler cannot play tricks on us by inlining | ||
if (argc >= 2) { | ||
b[0] = (uint8_t) strtol(argv[1], NULL, 16); | ||
} | ||
else { | ||
fprintf(stderr, "USAGE: %s hex_value\n", argv[0]); | ||
return 1; | ||
} | ||
// make sure b[0] is either 0 or 1 | ||
b[0] = !!b[0]; | ||
// declarations and markup here | ||
|
||
volatile issue_t func = issue; | ||
printf("%d\n", func(a, b)); | ||
|
||
return 0; | ||
} | ||
``` |
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,36 @@ | ||
--- | ||
ct: yes | ||
--- | ||
|
||
```c | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
typedef uint8_t(* issue_t)(const uint8_t*, const uint8_t*); | ||
|
||
uint8_t issue(const uint8_t *a, const uint8_t *b) { | ||
return !b[0]*a[0] + b[0]*a[1]; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
uint8_t a[2] ={2, 5}, b[2] = {0}; | ||
// b is our secret value containing array, we read its content from the | ||
// environment so the compiler cannot play tricks on us by inlining | ||
if (argc >= 2) { | ||
b[0] = (uint8_t) strtol(argv[1], NULL, 16); | ||
} | ||
else { | ||
fprintf(stderr, "USAGE: %s hex_value\n", argv[0]); | ||
return 1; | ||
} | ||
// make sure b[0] is either 0 or 1 | ||
b[0] = !!b[0]; | ||
// declarations and markup here | ||
|
||
volatile issue_t func = issue; | ||
printf("%d\n", func(a, b)); | ||
|
||
return 0; | ||
} | ||
``` |
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,45 @@ | ||
--- | ||
ct: no | ||
--- | ||
|
||
```c | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
typedef int(* issue_t)(const uint64_t*, const uint64_t*); | ||
|
||
#define THE_SIZE 9 | ||
|
||
int comparator(const uint64_t *a, const uint64_t *b) { | ||
return (memcmp(a, b, sizeof(uint64_t) * THE_SIZE) == 0); | ||
} | ||
|
||
int issue(const uint64_t *a, const uint64_t *b) { | ||
int ret = 0; | ||
for (int i = 2;i < 3;i += 2) { | ||
ret |= comparator(a,b); | ||
} | ||
return ret; | ||
} | ||
|
||
int main(int argc, char *argv[]){ | ||
uint64_t a[THE_SIZE] = {0}, b[THE_SIZE] = {0}, c[THE_SIZE] = {0}; | ||
// c is our secret value containing array, we read its content from the | ||
// environment so the compiler cannot play tricks on us by inlining | ||
if (argc >= 2) { | ||
memset(c, (uint64_t) argv[1][0], THE_SIZE*sizeof(uint64_t)); | ||
} | ||
else { | ||
fprintf(stderr, "USAGE: %s hex_value\n", argv[0]); | ||
return 1; | ||
} | ||
// declarations and markup here | ||
|
||
volatile issue_t func = issue; | ||
printf("%d\n", func(a, b)); | ||
printf("%d\n", func(a, c)); | ||
|
||
return 0; | ||
} | ||
``` |
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,79 @@ | ||
--- | ||
ct: yes | ||
--- | ||
|
||
```c | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define _GNU_SOURCE | ||
#include <unistd.h> | ||
#include <sys/syscall.h> | ||
|
||
typedef void(* issue_t)(uint8_t*, size_t); | ||
|
||
#if defined(__linux__) && defined(SYS_getrandom) | ||
void issue(uint8_t *out, size_t outlen) { | ||
while(outlen > 0) { | ||
ssize_t ret = syscall(SYS_getrandom, out, outlen, 0); | ||
if((ret == -1) && (errno == EINTR)) { | ||
continue; | ||
} | ||
else if(ret == -1) { | ||
fprintf(stderr, "Error while executing syscall getrandom\n"); | ||
abort(); | ||
} | ||
out += ret; | ||
outlen -= ret; | ||
} | ||
} | ||
#else | ||
void issue(uint8_t *out, size_t outlen) { | ||
int fd = -1; | ||
while(fd == -1) { | ||
fd = open("/dev/urandom", O_RDONLY); | ||
if((fd == -1) && (errno == EINTR)) { | ||
continue; | ||
} | ||
else if(fd == -1) { | ||
fprintf(stderr, "Error while opening /dev/urandom\n"); | ||
abort(); | ||
} | ||
} | ||
|
||
while(outlen > 0) { | ||
ssize_t ret = read(fd, out, outlen); | ||
if((ret == -1) && (errno == EINTR)) { | ||
continue; | ||
} | ||
else if(ret == -1) { | ||
close(fd); | ||
fprintf(stderr, "Error while reading from /dev/urandom\n"); | ||
abort(); | ||
} | ||
|
||
out += ret; | ||
outlen -= ret; | ||
} | ||
close(fd); | ||
} | ||
#endif | ||
|
||
int main(void) { | ||
uint8_t out[1] = {0}; | ||
size_t size = 1; | ||
// this test has no secret variables from the start, but the randomness from | ||
// /dev/urandom or SYS_getrandom may be the input to some function generating | ||
// a secret | ||
|
||
// declarations and markup here | ||
|
||
volatile issue_t func = issue; | ||
func(out, size); | ||
|
||
return 0; | ||
} | ||
``` |
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,64 @@ | ||
--- | ||
ct: no | ||
--- | ||
|
||
```c | ||
#include <fcntl.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
typedef uint8_t(* issue_t)(const uint8_t, const uint8_t, const uint8_t, const uint8_t); | ||
|
||
uint8_t issue(const uint8_t c, const uint8_t a, const uint8_t b, const uint8_t len) { | ||
uint8_t d = !!c; | ||
if(len <= 254) { | ||
return d*a + (1-d)*b; | ||
} | ||
else { | ||
if(c) { | ||
return a; | ||
} | ||
else { | ||
return b; | ||
} | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
uint8_t a = 2, b = 5, c = 0; | ||
// c is our secret value, we read its content from the environment so the | ||
// compiler cannot play tricks on us by inlining | ||
if (argc >= 2) { | ||
c = (uint8_t) strtol(argv[1], NULL, 16); | ||
} | ||
else { | ||
fprintf(stderr, "USAGE: %s hex_value\n", argv[0]); | ||
return 1; | ||
} | ||
// declarations and markup here | ||
|
||
uint8_t len = 1; | ||
|
||
int fd = open("/dev/urandom", O_RDONLY); | ||
if(fd != -1) { | ||
ssize_t ret = read(fd, &len, 1); | ||
close(fd); | ||
if(ret == -1) { | ||
fprintf(stderr, "Error while reading from /dev/urandom\n"); | ||
abort(); | ||
} | ||
} | ||
else { | ||
fprintf(stderr, "Error while opening /dev/urandom\n"); | ||
abort(); | ||
} | ||
|
||
|
||
volatile issue_t func = issue; | ||
printf("%d\n", func(c, a, b, len)); | ||
|
||
return 0; | ||
} | ||
``` |
Oops, something went wrong.