<commit_before>/*
 * GraxRabble
 * Demo programs for libsodium.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sodium.h> /* library header */

#include "utils.h" /* utility functions shared by demos */

/*
 * Signs a message with secret key which will authenticate a message.
 * Everybody else can use the public key to ensure that the message is both
 * valid and untampered.
 *
 * Note that the signed message will have 16 bytes of signature prepended.
 * Ensure that the signed buffer is at least crypto_sign_BYTES longer then
 * the actual message.
 */
static int
sign(void)
{
    unsigned char pk[crypto_sign_PUBLICKEYBYTES];         /* Bob public */
    unsigned char sk[crypto_sign_SECRETKEYBYTES];         /* Bob secret */
    unsigned char m[MAX_INPUT_SIZE];                      /* message */
    unsigned char sm[MAX_INPUT_SIZE + crypto_sign_BYTES]; /* signed message */
    unsigned long long int mlen;                          /* message length */
    unsigned long long int smlen;                         /* signed length */
    int r;

    puts("Example: crypto_sign\n");

    puts("Generating keypair...");
    crypto_sign_keypair(pk, sk); /* generate Bob's keys */

    fputs("Public: ", stdout);
    print_hex(pk, sizeof pk);
    putc('\n', stdout);
    fputs("Secret: ", stdout);
    print_hex(sk, sizeof sk);
    puts("\n");

    /* read input */
    mlen = prompt_input("a message", (char*)m,
                        sizeof m - crypto_sign_BYTES, 1);
    putc('\n', stdout);

    puts("Notice the message has no prepended padding");
    print_hex(m, mlen);
    putchar('\n');
    putchar('\n');

    printf("Signing message with %s...\n", crypto_sign_primitive());
    crypto_sign(sm, &smlen, m, mlen, sk);

    puts("Notice the signed message has prepended signature");
    print_hex(sm, smlen);
    putchar('\n');
    putchar('\n');

    fputs("Signature: ", stdout);
    print_hex(sm, crypto_sign_BYTES);
    putchar('\n');
    fputs("Message: ", stdout);
    fwrite(sm + crypto_sign_BYTES, 1U, smlen - crypto_sign_BYTES, stdout);
    putchar('\n');

    puts("Validating message...");
    r = crypto_sign_open(m, &mlen, sm, smlen, pk);

    print_verification(r);<commit_msg>sign demo: fix weird max message length<commit_after>/*
 * GraxRabble
 * Demo programs for libsodium.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sodium.h> /* library header */

#include "utils.h" /* utility functions shared by demos */

/*
 * Signs a message with secret key which will authenticate a message.
 * Everybody else can use the public key to ensure that the message is both
 * valid and untampered.
 *
 * Note that the signed message will have 16 bytes of signature prepended.
 * Ensure that the signed buffer is at least crypto_sign_BYTES longer then
 * the actual message.
 */
static int
sign(void)
{
    unsigned char pk[crypto_sign_PUBLICKEYBYTES];         /* Bob public */
    unsigned char sk[crypto_sign_SECRETKEYBYTES];         /* Bob secret */
    unsigned char m[MAX_INPUT_SIZE];                      /* message */
    unsigned char sm[MAX_INPUT_SIZE + crypto_sign_BYTES]; /* signed message */
    unsigned long long int mlen;                          /* message length */
    unsigned long long int smlen;                         /* signed length */
    int r;

    puts("Example: crypto_sign\n");

    puts("Generating keypair...");
    crypto_sign_keypair(pk, sk); /* generate Bob's keys */

    fputs("Public: ", stdout);
    print_hex(pk, sizeof pk);
    putc('\n', stdout);
    fputs("Secret: ", stdout);
    print_hex(sk, sizeof sk);
    puts("\n");

    /* read input */
    mlen = prompt_input("a message", (char*)m, sizeof m, 1);
    putchar('\n');

    puts("Notice the message has no prepended padding");
    print_hex(m, mlen);
    putchar('\n');
    putchar('\n');

    printf("Signing message with %s...\n", crypto_sign_primitive());
    crypto_sign(sm, &smlen, m, mlen, sk);

    puts("Notice the signed message has prepended signature");
    print_hex(sm, smlen);
    putchar('\n');
    putchar('\n');

    fputs("Signature: ", stdout);
    print_hex(sm, crypto_sign_BYTES);
    putchar('\n');
    fputs("Message: ", stdout);
    fwrite(sm + crypto_sign_BYTES, 1U, smlen - crypto_sign_BYTES, stdout);
    putchar('\n');

    puts("Validating message...");
    r = crypto_sign_open(m, &mlen, sm, smlen, pk);

    print_verification(r);
{'fraction_non_alphanumeric': 0.1351839313924622, 'fraction_numerical': 0.0018054615211013315, 'mean_word_length': 2.8305963699222128, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6289220', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1403, 'n_words': 413}