[gnutls-devel] Guile-GnuTLS | aead.scm fails on Mac OS (#13)

Read-only notification of GnuTLS library development activities gnutls-devel at lists.gnutls.org
Tue Jul 18 19:03:26 CEST 2023




Vivien Kraus Would Rather Not Be On Gitlab_com commented: https://gitlab.com/gnutls/guile/-/issues/13#note_1475182161

Can you compile this sample code and run it? It should output "OK":

```c
#include <gnutls/crypto.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int
main ()
{
  static const gnutls_cipher_algorithm_t algo = GNUTLS_CIPHER_AES_256_GCM;
  static const char *key = "the secret key is 32 bytes long.";
  gnutls_datum_t datum_key;
  datum_key.data = (unsigned char *) key;
  datum_key.size = strlen (key);
  gnutls_aead_cipher_hd_t handle;
  if (gnutls_aead_cipher_init (&handle, algo, &datum_key))
    {
      return EXIT_FAILURE;
    }
  static const char *nonce = "Never encrypt more data with this nonce";
  static const char *auth = "Additional secret data";
  static const int tag_size = 16;
  static const char *data = "Confidential data.";
  size_t used_size = tag_size + strlen (data);
  char output[used_size];
  if (gnutls_aead_cipher_encrypt (handle,
                                  nonce, strlen (nonce),
                                  auth, strlen (auth),
                                  tag_size,
                                  data, strlen (data),
                                  output, &used_size))
    {
      return EXIT_FAILURE;
    }
  if (used_size != 34)
    {
      return EXIT_FAILURE;
    }
  if (output[0] != (char) 165)
    {
      return EXIT_FAILURE;
    }
  gnutls_aead_cipher_deinit (handle);
  fprintf (stderr, "OK\n");
  return EXIT_SUCCESS;
}
```

```shell
gcc main.c $(pkg-config --cflags gnutls) $(pkg-config --libs gnutls) && ./a.out
```

I get:

```
OK
```

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/guile/-/issues/13#note_1475182161
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnutls-devel/attachments/20230718/9c5fa346/attachment-0001.html>


More information about the Gnutls-devel mailing list