File: hasvalgrind.c

package info (click to toggle)
tinyssh 20250501-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,388 kB
  • sloc: ansic: 20,245; sh: 1,582; python: 1,449; makefile: 913
file content (40 lines) | stat: -rw-r--r-- 892 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <valgrind/memcheck.h>

/* return zero for all inputs */
static unsigned char z(unsigned char x) {

    unsigned long long z = (unsigned long long) x + 1ULL;
    unsigned long long t = z;
    long long i;

    for (i = 6; i >= 0; --i) {
        t = (t * t) % 257;
        t = (t * z) % 257;
    }
    t = (t * z) % 257;
    return (unsigned char) t - 1;
}

static void secret(void *xv, long long xlen) {
    VALGRIND_MAKE_MEM_UNDEFINED(xv, xlen);
}

static void public(void *xv, long long xlen) {
    VALGRIND_MAKE_MEM_DEFINED(xv, xlen);
}

int main(int argc, char **argv) {

    unsigned char buf[32] = {1};
    unsigned char ret = 0;
    unsigned long long i;

    (void) argc;
    (void) argv;

    secret(buf, sizeof buf);
    for (i = 0; i < sizeof buf; ++i) ret |= z(buf[i]);
    public(buf, sizeof buf);
    for (i = 0; i < sizeof buf; ++i) ret |= z(buf[i]);
    return ret;
}