00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include <sys/types.h>
00025 #include <sys/stat.h>
00026 #include <unistd.h>
00027 #include "sizes.h"
00028 #include "mceliece.h"
00029
00030 __inline unsigned long long rdtsc()
00031 {
00032 unsigned long long x;
00033 __asm__ volatile (".byte 0x0f, 0x31" :"=A" (x));
00034 return x;
00035 }
00036
00037 int main(int argc, char ** argv) {
00038 int m, t;
00039 unsigned char pk[PUBLICKEY_BYTES];
00040 unsigned char message[MESSAGE_BYTES], ciphertext[CIPHERTEXT_BYTES];
00041 int n;
00042 int size_n, data_bytes;
00043 FILE * fichier, * output;
00044 struct stat buf;
00045
00046 if (argc <= 3) {
00047 printf("syntax: %s public_key_file cleartext_file output_file\n", argv[0]);
00048 exit(0);
00049 }
00050
00051 fichier = fopen(argv[1], "r");
00052 fread(&m, sizeof(int), 1, fichier);
00053 fread(&t, sizeof(int), 1, fichier);
00054 if ((m != EXT_DEGREE) || (t != NB_ERRORS)) {
00055 fprintf(stderr, "invalid public key file (m,t)=(%d,%d) instead of (%d,%d)\n", m, t, EXT_DEGREE, NB_ERRORS);
00056 exit(0);
00057 }
00058 fread(pk, 1, PUBLICKEY_BYTES, fichier);
00059 fclose(fichier);
00060
00061 fichier = fopen(argv[2], "r");
00062 output = fopen(argv[3], "w");
00063
00064 stat(argv[2], &buf);
00065 n = buf.st_size;
00066 size_n = sizeof (n);
00067
00068 memcpy(message, &n, size_n);
00069 fread(message + size_n, 1, MESSAGE_BYTES - size_n, fichier);
00070
00071 n -= MESSAGE_BYTES - size_n;
00072
00073 while (n > 0) {
00074 encrypt_block_ss(ciphertext, message, pk);
00075 fwrite(ciphertext, 1, CIPHERTEXT_BYTES, output);
00076 fread(message, 1, MESSAGE_BYTES, fichier);
00077 n -= MESSAGE_BYTES;
00078 }
00079
00080 encrypt_block_ss(ciphertext, message, pk);
00081 fwrite(ciphertext, 1, CIPHERTEXT_BYTES, output);
00082
00083 fclose(fichier);
00084 fclose(output);
00085
00086 return 0;
00087 }