From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../Public-Key-Algorithmen/PKA-Prakt1/src/main.c | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Master/Public-Key-Algorithmen/PKA-Prakt1/src/main.c (limited to 'Master/Public-Key-Algorithmen/PKA-Prakt1/src/main.c') diff --git a/Master/Public-Key-Algorithmen/PKA-Prakt1/src/main.c b/Master/Public-Key-Algorithmen/PKA-Prakt1/src/main.c new file mode 100644 index 0000000..2987966 --- /dev/null +++ b/Master/Public-Key-Algorithmen/PKA-Prakt1/src/main.c @@ -0,0 +1,88 @@ +/* + * main.c + * + * Created on: 23.04.2010 + * Author: sven + */ +#include +#include +#include +#include +#include + +#define HI(x) (x >> 16) +#define LO(x) (x & 0x0000FFFF) + +void mulc(uint32_t *u, uint32_t *v, uint32_t a, uint32_t b) +{ + uint32_t t; + t = LO(a) * LO(b); + *v = LO(t); + t = HI(t) + HI(a) * LO(b); + *u = HI(t); + t = LO(t) + LO(a) * HI(b); + *v |= LO(t) << 16; + *u += HI(t) + HI(a) * HI(b); +} +void mula(uint32_t *u, uint32_t *v, uint32_t a, uint32_t b) +{ + asm + ( + "mov %2,%%eax\n" + "mul %3\n" + "mov %%edx, %0\n" + "mov %%eax, %1" + :"=r"(*u),"=r"(*v) + :"r"(a),"r"(b) + ); +} +void initRandomizer() +{ + srand(time(NULL)); +} +uint32_t getRandomUint32() +{ + uint32_t res = rand(); + if(res % 2) + { + return (res | 1<<31); + } + return res; +} +int main(int argc, char* argv[]) +{ + initRandomizer(); + uint32_t a = getRandomUint32(); + uint32_t b = getRandomUint32(); + uint32_t u,v; + uint32_t counter; + uint32_t outerCnt; + const uint32_t NUM_INNER_LOOPS = 1000000; + const uint32_t NUM_OUTER_LOOPS = 1000; + struct timeval startc; + struct timeval endc; + struct timeval starta; + struct timeval enda; + long diffCsum = 0,diffAsum = 0; + for(outerCnt=0;outerCnt