summaryrefslogtreecommitdiffstats
path: root/Master/Public-Key-Algorithmen/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Public-Key-Algorithmen/main.c')
-rw-r--r--Master/Public-Key-Algorithmen/main.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/Master/Public-Key-Algorithmen/main.c b/Master/Public-Key-Algorithmen/main.c
new file mode 100644
index 0000000..51d92bb
--- /dev/null
+++ b/Master/Public-Key-Algorithmen/main.c
@@ -0,0 +1,53 @@
+/*
+ * main.c
+ *
+ * Created on: 23.04.2010
+ * Author: eisenhauer
+ */
+#include "stdlib.h"
+#include "unistd.h"
+#include "stdio.h"
+
+#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"
+ : "=c"(*u),"=d"(*v)
+ : "a"(a),"b"(b)
+ );
+}
+
+int main(int args, char* argv[])
+{
+ uint32_t resLow;
+ uint32_t resHigh;
+ uint32_t a = 1261938865;
+ uint32_t b = 1446688886;
+
+ mulc(&resHigh,&resLow,a,b);
+ printf("%u * %u = %u %u\n",a,b,resHigh,resLow);
+ resHigh = 0;
+ resLow = 0;
+ printf("%u %u\n",resHigh,resLow);
+ mula(&resHigh,&resLow,a,b);
+ printf("%u * %u = %u %u\n",a,b,resHigh,resLow);
+ return EXIT_SUCCESS;
+}