/** * oath_done: * * This function deinitializes the OATH library, which were * initialized using oath_init(). After calling this function, no * other OATH library function may be called except for to * re-initialize the library using oath_init(). * * Returns: On success, %OATH_OK (zero) is returned, otherwise an * error code is returned. **/ int oath_done (void) { gc_done (); return OATH_OK; }
/** * gnutls_global_deinit - This function deinitializes the global data * * This function deinitializes the global data, that were initialized * using gnutls_global_init(). * * Note! This function is not thread safe. See the discussion for * gnutls_global_init() for more information. * **/ void gnutls_global_deinit (void) { if (_gnutls_init == 1) { #if HAVE_WINSOCK WSACleanup (); #endif asn1_delete_structure (&_gnutls_gnutls_asn); asn1_delete_structure (&_gnutls_pkix1_asn); gc_done (); } _gnutls_init--; }
int main (int argc, char *argv[]) { Gc_rc rc; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } gc_done (); return 0; }
int main (int argc, char *argv[]) { Gc_rc rc; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } { char *key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; size_t key_len = 16; char *data = "Hi There"; size_t data_len = 8; char *digest = "\x67\x5b\x0b\x3a\x1b\x4d\xdf\x4e\x12\x48" "\x72\xda\x6c\x2f\x63\x2b\xfe\xd9\x57\xe9"; char out[GC_SHA1_DIGEST_SIZE]; if (gc_hmac_sha1 (key, key_len, data, data_len, out) != 0) { printf ("call failure\n"); return 1; } if (memcmp (digest, out, GC_SHA1_DIGEST_SIZE) != 0) { size_t i; printf ("hash 1 mismatch. expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", digest[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } } gc_done (); return 0; }
int main (int argc, char *argv[]) { Gc_rc rc; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } { char *key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; size_t key_len = 20; char *data = "Hi There"; size_t data_len = 8; char *digest = "\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20\x3a\x12\x68\x54"; char out[GC_SHA512_DIGEST_SIZE]; if (gc_hmac_sha512 (key, key_len, data, data_len, out) != 0) { printf ("call failure\n"); return 1; } if (memcmp (digest, out, GC_SHA512_DIGEST_SIZE) != 0) { size_t i; printf ("hash 1 mismatch. expected:\n"); for (i = 0; i < GC_SHA512_DIGEST_SIZE; i++) printf ("%02x ", digest[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < GC_SHA512_DIGEST_SIZE; i++) printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } } gc_done (); return 0; }
int main (int argc, char *argv[]) { Gc_rc rc; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } { char *key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"; size_t key_len = 20; char *data = "Hi There"; size_t data_len = 8; char *digest = "\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7"; char out[GC_SHA256_DIGEST_SIZE]; if (gc_hmac_sha256 (key, key_len, data, data_len, out) != 0) { printf ("call failure\n"); return 1; } if (memcmp (digest, out, GC_SHA256_DIGEST_SIZE) != 0) { size_t i; printf ("hash 1 mismatch. expected:\n"); for (i = 0; i < GC_SHA256_DIGEST_SIZE; i++) printf ("%02x ", digest[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < GC_SHA256_DIGEST_SIZE; i++) printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } } gc_done (); return 0; }
int main (int argc, char *argv[]) { Gc_rc rc; gc_hash_handle h; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } /* Test vectors from RFC 1320. */ { const char *in = "abc"; size_t inlen = strlen (in); const char *expect = "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d"; char out[16]; const char *p; /* MD4 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b */ if (gc_md4 (in, inlen, out) != 0) { printf ("gc_md4 call failed\n"); return 1; } if (memcmp (out, expect, 16) != 0) { size_t i; printf ("md4 1 mismatch. expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", expect[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } if (gc_hash_buffer (GC_MD4, in, inlen, out) != 0) { printf ("gc_hash_buffer(MD4) call failed\n"); return 1; } if (memcmp (out, expect, 16) != 0) { size_t i; printf ("md4 1 mismatch. expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", expect[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } if (gc_hash_digest_length (GC_MD4) != 16) { printf ("gc_hash_digest_length (GC_MD4) failed\n"); return 1; } if ((rc = gc_hash_open (GC_MD4, 0, &h)) != GC_OK) { printf ("gc_hash_open(GC_MD4) failed (%d)\n", rc); return 1; } gc_hash_write (h, inlen, in); p = gc_hash_read (h); if (!p) { printf ("gc_hash_read failed\n"); return 1; } if (memcmp (p, expect, 16) != 0) { size_t i; printf ("md4 1 mismatch. expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", expect[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", p[i] & 0xFF); printf ("\n"); return 1; } gc_hash_close (h); } gc_done (); return 0; }
int main (int argc, char *argv[]) { gc_cipher_handle ctx; /* Test vector from Cryptlib via Libgcrypt labeled there: "from the State/Commerce Department". */ static char key_1[] = { 0x61, 0x8A, 0x63, 0xD2, 0xFB }; static char plaintext_1[] = { 0xDC, 0xEE, 0x4C, 0xF9, 0x2C }; static const char ciphertext_1[] = { 0xF1, 0x38, 0x29, 0xC9, 0xDE }; char scratch[16]; Gc_rc rc; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } rc = gc_cipher_open (GC_ARCFOUR40, GC_STREAM, &ctx); if (rc != GC_OK) return 1; rc = gc_cipher_setkey (ctx, sizeof (key_1), key_1); if (rc != GC_OK) return 1; memcpy (scratch, plaintext_1, sizeof (plaintext_1)); rc = gc_cipher_encrypt_inline (ctx, sizeof (plaintext_1), scratch); if (rc != GC_OK) return 1; if (memcmp (scratch, ciphertext_1, sizeof (ciphertext_1))) { size_t i; printf ("expected:\n"); for (i = 0; i < 5; i++) printf ("%02x ", scratch[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 5; i++) printf ("%02x ", ciphertext_1[i] & 0xFF); printf ("\n"); return 1; } /* decrypt */ rc = gc_cipher_setkey (ctx, sizeof (key_1), key_1); if (rc != GC_OK) return 1; rc = gc_cipher_decrypt_inline (ctx, sizeof (plaintext_1), scratch); if (rc != GC_OK) return 1; if (memcmp (scratch, plaintext_1, sizeof (plaintext_1))) { size_t i; printf ("expected:\n"); for (i = 0; i < 5; i++) printf ("%02x ", plaintext_1[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 5; i++) printf ("%02x ", scratch[i] & 0xFF); printf ("\n"); return 1; } gc_done (); return 0; }
void pony_recv_done(pony_ctx_t* ctx) { gc_handlestack(ctx); gc_done(actor_gc(ctx->current)); }
void pony_send_done(pony_ctx_t* ctx) { gc_handlestack(ctx); gc_sendacquire(ctx); gc_done(actor_gc(ctx->current)); }
int main (int argc, char *argv[]) { Gc_rc rc; gc_hash_handle h; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } { char *in = "abcdefgh"; size_t inlen = strlen (in); char *expect = "\x42\x5a\xf1\x2a\x07\x43\x50\x2b" "\x32\x2e\x93\xa0\x15\xbc\xf8\x68\xe3\x24\xd5\x6a"; char out[20]; const char *p; if (gc_sha1 (in, inlen, out) != 0) { printf ("gc_sha1 call failed\n"); return 1; } if (memcmp (out, expect, 20) != 0) { size_t i; printf ("sha1 mismatch. expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", expect[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } rc = gc_hash_buffer (GC_SHA1, "abcdefgh", 8, out); if (rc != GC_OK) { printf ("gc_hash_buffer(sha1) call failed: %d\n", rc); return 1; } if (memcmp (out, expect, 20) != 0) { size_t i; printf ("sha1' mismatch. expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", expect[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } if (gc_hash_digest_length (GC_SHA1) != 20) { printf ("gc_hash_digest_length (GC_SHA1) failed\n"); return 1; } if ((rc = gc_hash_open (GC_SHA1, 0, &h)) != GC_OK) { printf ("gc_hash_open(GC_SHA1) failed (%d)\n", rc); return 1; } gc_hash_write (h, inlen, in); p = gc_hash_read (h); if (!p) { printf ("gc_hash_read failed\n"); return 1; } if (memcmp (p, expect, 20) != 0) { size_t i; printf ("sha1 1 mismatch. expected:\n"); for (i = 0; i < 20; i++) printf ("%02x ", expect[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 20; i++) printf ("%02x ", p[i] & 0xFF); printf ("\n"); return 1; } gc_hash_close (h); } gc_done (); return 0; }
int main (int argc, char *argv[]) { gc_cipher_handle ctx; Gc_rc rc; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } /* * DES Maintenance Test */ { int i; char key[8] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }; char input[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; char result[8] = { 0x24, 0x6e, 0x9d, 0xb9, 0xc5, 0x50, 0x38, 0x1a }; char temp1[8], temp2[8], temp3[8]; for (i = 0; i < 64; ++i) { rc = gc_cipher_open (GC_DES, GC_ECB, &ctx); if (rc != GC_OK) return 1; rc = gc_cipher_setkey (ctx, 8, key); if (rc != GC_OK) return 1; memcpy (temp1, input, 8); rc = gc_cipher_encrypt_inline (ctx, 8, temp1); if (rc != GC_OK) return 1; memcpy (temp2, temp1, 8); rc = gc_cipher_encrypt_inline (ctx, 8, temp2); if (rc != GC_OK) return 1; rc = gc_cipher_setkey (ctx, 8, temp2); if (rc != GC_OK) return 1; memcpy (temp3, temp1, 8); rc = gc_cipher_decrypt_inline (ctx, 8, temp3); if (rc != GC_OK) return 1; memcpy (key, temp3, 8); memcpy (input, temp1, 8); } if (memcmp (temp3, result, 8)) return 1; } gc_done (); return 0; }
int main (int argc, char *argv[]) { Gc_rc rc; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } { char buf[16]; char key[] = "\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00"; char pt[] = "\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00"; char ct[] = "\xC3\x4C\x05\x2C\xC0\xDA\x8D\x73" "\x45\x1A\xFE\x5F\x03\xBE\x29\x7F"; gc_cipher_handle ctx; size_t i; rc = gc_cipher_open (GC_AES128, GC_ECB, &ctx); if (rc != GC_OK) return 1; rc = gc_cipher_setkey (ctx, 16, key); if (rc != GC_OK) return 1; memcpy (buf, pt, 16); for (i = 0; i < 10000; i++) { rc = gc_cipher_encrypt_inline (ctx, 16, buf); if (rc != GC_OK) { printf ("encrypt failed %d\n", rc); return 1; } } if (memcmp (buf, ct, 16) != 0) { size_t i; printf ("expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", ct[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", buf[i] & 0xFF); printf ("\n"); return 1; } for (i = 0; i < 10000; i++) { rc = gc_cipher_decrypt_inline (ctx, 16, buf); if (rc != GC_OK) { printf ("decrypt failed %d\n", rc); return 1; } } if (memcmp (buf, pt, 16) != 0) { size_t i; printf ("expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", pt[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", buf[i] & 0xFF); printf ("\n"); return 1; } gc_cipher_close (ctx); } { char buf[16]; char iv[] = "\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00"; char key[] = "\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00"; char pt[] = "\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00"; char ct[] = "\x66\xe9\x4b\xd4\xef\x8a\x2c\x3b" "\x88\x4c\xfa\x59\xca\x34\x2b\x2e"; gc_cipher_handle ctx; size_t i; rc = gc_cipher_open (GC_AES128, GC_CBC, &ctx); if (rc != GC_OK) return 1; rc = gc_cipher_setkey (ctx, 16, key); if (rc != GC_OK) return 1; rc = gc_cipher_setiv (ctx, 16, iv); if (rc != GC_OK) return 1; memcpy (buf, pt, 16); for (i = 0; i < 10000; i++) { rc = gc_cipher_encrypt_inline (ctx, 16, buf); if (rc != GC_OK) { printf ("encrypt failed %d\n", rc); return 1; } } if (memcmp (buf, ct, 16) != 0) { size_t i; printf ("expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", ct[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", buf[i] & 0xFF); printf ("\n"); return 1; } gc_cipher_close (ctx); } gc_done (); return 0; }
int main (int argc, char *argv[]) { gc_cipher_handle ctx; /* Test vectors from RFC 2268. */ static char key[8] = "\xff\xff\xff\xff\xff\xff\xff\xff"; static char plaintext[8] = "\xff\xff\xff\xff\xff\xff\xff\xff"; static const char ciphertext[8] = "\x27\x8b\x27\xe4\x2e\x2f\x0d\x49"; char scratch[16]; Gc_rc rc; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } rc = gc_cipher_open (GC_ARCTWO40, GC_ECB, &ctx); if (rc != GC_OK) return 1; rc = gc_cipher_setkey (ctx, sizeof (key), key); if (rc != GC_OK) return 1; memcpy (scratch, plaintext, sizeof (plaintext)); rc = gc_cipher_encrypt_inline (ctx, sizeof (plaintext), scratch); if (rc != GC_OK) return 1; if (memcmp (scratch, ciphertext, sizeof (ciphertext))) { size_t i; printf ("expected:\n"); for (i = 0; i < 5; i++) printf ("%02x ", scratch[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 5; i++) printf ("%02x ", ciphertext[i] & 0xFF); printf ("\n"); return 1; } /* decrypt */ rc = gc_cipher_setkey (ctx, sizeof (key), key); if (rc != GC_OK) return 1; rc = gc_cipher_decrypt_inline (ctx, sizeof (plaintext), scratch); if (rc != GC_OK) return 1; if (memcmp (scratch, plaintext, sizeof (plaintext))) { size_t i; printf ("expected:\n"); for (i = 0; i < 5; i++) printf ("%02x ", plaintext[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 5; i++) printf ("%02x ", scratch[i] & 0xFF); printf ("\n"); return 1; } gc_done (); return 0; }
int main (int argc, char *argv[]) { Gc_rc rc; gc_hash_handle h; rc = gc_init (); if (rc != GC_OK) { printf ("gc_init() failed\n"); return 1; } /* Test vectors from RFC 1319. */ { char *in = "abcdefghijklmnopqrstuvwxyz"; size_t inlen = strlen (in); char *expect = "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47\x94\x0b"; char out[16]; const char *p; if (gc_md2 (in, inlen, out) != 0) { printf ("gc_md2 call failed\n"); return 1; } if (memcmp (out, expect, 16) != 0) { size_t i; printf ("md2 1 mismatch. expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", expect[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } if (gc_hash_buffer (GC_MD2, in, inlen, out) != 0) { printf ("gc_hash_buffer(MD2) call failed\n"); return 1; } if (memcmp (out, expect, 16) != 0) { size_t i; printf ("md2 2 mismatch. expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", expect[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", out[i] & 0xFF); printf ("\n"); return 1; } if (gc_hash_digest_length (GC_MD2) != 16) { printf ("gc_hash_digest_length (GC_MD2) failed\n"); return 1; } if ((rc = gc_hash_open (GC_MD2, 0, &h)) != GC_OK) { printf ("gc_hash_open(GC_MD2) failed (%d)\n", rc); return 1; } gc_hash_write (h, inlen, in); p = gc_hash_read (h); if (!p) { printf ("gc_hash_read failed\n"); return 1; } if (memcmp (p, expect, 16) != 0) { size_t i; printf ("md2 3 mismatch. expected:\n"); for (i = 0; i < 16; i++) printf ("%02x ", expect[i] & 0xFF); printf ("\ncomputed:\n"); for (i = 0; i < 16; i++) printf ("%02x ", p[i] & 0xFF); printf ("\n"); return 1; } gc_hash_close (h); } gc_done (); return 0; }