summaryrefslogtreecommitdiff
path: root/other/fun
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-29 17:55:58 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-29 17:55:58 -0400
commitea994606fe4ee57f2d6ac1ddfb2225f8a1aacef0 (patch)
tree4c7f407486c8780ceaf68bbf17f7266027ed9d05 /other/fun
parent85940f94b2560f87988da8e793eb8998c5b77ead (diff)
parent82b8927af7f68bbfbf83bbb5ffbc747de7bc288f (diff)
Merge branch 'master' of https://github.com/JamoBox/ProjectTox-Core into JamoBox-master
Conflicts: toxcore/LAN_discovery.h
Diffstat (limited to 'other/fun')
-rw-r--r--other/fun/sign.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/other/fun/sign.c b/other/fun/sign.c
index bcf54c3a..423d974a 100644
--- a/other/fun/sign.c
+++ b/other/fun/sign.c
@@ -1,5 +1,5 @@
1/* Binary signer/checker using ed25519 1/* Binary signer/checker using ed25519
2 * 2 *
3 * Compile with: 3 * Compile with:
4 * gcc -o sign sign.c -lsodium 4 * gcc -o sign sign.c -lsodium
5 * 5 *
@@ -60,6 +60,7 @@ int main(int argc, char *argv[])
60{ 60{
61 unsigned char pk[crypto_sign_ed25519_PUBLICKEYBYTES]; 61 unsigned char pk[crypto_sign_ed25519_PUBLICKEYBYTES];
62 unsigned char sk[crypto_sign_ed25519_SECRETKEYBYTES]; 62 unsigned char sk[crypto_sign_ed25519_SECRETKEYBYTES];
63
63 if (argc == 2 && argv[1][0] == 'g') { 64 if (argc == 2 && argv[1][0] == 'g') {
64 crypto_sign_ed25519_keypair(pk, sk); 65 crypto_sign_ed25519_keypair(pk, sk);
65 printf("Public key:\n"); 66 printf("Public key:\n");
@@ -89,19 +90,22 @@ int main(int argc, char *argv[])
89 unsigned long long smlen; 90 unsigned long long smlen;
90 char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); 91 char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2);
91 crypto_sign_ed25519(sm, &smlen, data, size, secret_key); 92 crypto_sign_ed25519(sm, &smlen, data, size, secret_key);
93
92 if (smlen - size != crypto_sign_ed25519_BYTES) 94 if (smlen - size != crypto_sign_ed25519_BYTES)
93 goto fail; 95 goto fail;
96
94 FILE *f = fopen(argv[4], "wb"); 97 FILE *f = fopen(argv[4], "wb");
95 98
96 if (f == NULL) 99 if (f == NULL)
97 goto fail; 100 goto fail;
98 memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); //Move signature from beginning to end of file. 101
102 memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); // Move signature from beginning to end of file.
99 103
100 if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) 104 if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen)
101 goto fail; 105 goto fail;
102 106
103 fclose(f); 107 fclose(f);
104 printf("Signed successfully\n"); 108 printf("Signed successfully.\n");
105 } 109 }
106 110
107 if (argc == 4 && argv[1][0] == 'c') { 111 if (argc == 4 && argv[1][0] == 'c') {
@@ -113,22 +117,24 @@ int main(int argc, char *argv[])
113 goto fail; 117 goto fail;
114 118
115 char *signe = malloc(size + crypto_sign_ed25519_BYTES); 119 char *signe = malloc(size + crypto_sign_ed25519_BYTES);
116 memcpy(signe, data + size - crypto_sign_ed25519_BYTES, crypto_sign_ed25519_BYTES);//Move signature from end to beginning of file. 120 memcpy(signe, data + size - crypto_sign_ed25519_BYTES,
121 crypto_sign_ed25519_BYTES); // Move signature from end to beginning of file.
117 memcpy(signe + crypto_sign_ed25519_BYTES, data, size - crypto_sign_ed25519_BYTES); 122 memcpy(signe + crypto_sign_ed25519_BYTES, data, size - crypto_sign_ed25519_BYTES);
118 unsigned long long smlen; 123 unsigned long long smlen;
119 char *m = malloc(size); 124 char *m = malloc(size);
120 unsigned long long mlen; 125 unsigned long long mlen;
121 126
122 if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) { 127 if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) {
123 printf("Failed checking sig\n"); 128 printf("Failed checking sig.\n");
124 goto fail; 129 goto fail;
125 } 130 }
126 printf("Checked successfully\n"); 131
132 printf("Checked successfully.\n");
127 } 133 }
128 134
129 return 0; 135 return 0;
130 136
131 fail: 137fail:
132 printf("FAIL\n"); 138 printf("FAIL\n");
133 return 1; 139 return 1;
134} 140}