int crypto_box_open(unsigned char *m, const unsigned char *c, unsigned long long clen, const unsigned char *n, const unsigned char *pk, const unsigned char *sk) { return crypto_box_curve25519xsalsa20poly1305_open(m, c, clen, n, pk, sk); }
main() { int i; if (crypto_box_curve25519xsalsa20poly1305_open( m,c,163,nonce,alicepk,bobsk ) == 0) { for (i = 32;i < 163;++i) { printf(",0x%02x",(unsigned int) m[i]); if (i % 8 == 7) printf("\n"); } printf("\n"); } return 0; }
/* * wrapper around crypto_box_open. * operates on buf "in place". * box contains nonce and auth tag data. */ static void pubdecryptmsg(uint8_t *buf, unsigned long long msglen, uint8_t *box, uint8_t *pubkey, uint8_t *seckey) { uint8_t *msg, *cmsg; cmsg = xmalloc(msglen + ENCZEROBYTES); memset(cmsg, 0, ENCBOXZEROBYTES); memcpy(cmsg + ENCBOXZEROBYTES, box + ENCNONCEBYTES, ENCBOXBYTES); memcpy(cmsg + ENCZEROBYTES, buf, msglen); msg = xmalloc(msglen + ENCZEROBYTES); if (crypto_box_curve25519xsalsa20poly1305_open(msg, cmsg, msglen + ENCZEROBYTES, box, pubkey, seckey) == -1) errx(1, "decryption failed"); xfree(cmsg, msglen + ENCZEROBYTES); memcpy(buf, msg + ENCZEROBYTES, msglen); xfree(msg, msglen + ENCZEROBYTES); }