Can i decrypt intial QUIC payload using libgcrypt. [closed]

asked 2019-05-08 12:08:35 +0000

updated 2019-05-08 12:11:56 +0000

grahamb gravatar image

Hey All, Just a newbie asking silly questions. I was trying to decrypt initial payload for quic . I tried using libgcrypt , but failed to decrypt another payload using a sample code.

#include <gcrypt.h>
#include <string.h>

void main()
{
    #define GCRY_CIPHER GCRY_CIPHER_SHA256   // Pick the cipher here
    #define GCRY_C_MODE GCRY_CIPHER_MODE_OCB // Pick the cipher mode here

    gcry_error_t     gcryError;
    gcry_cipher_hd_t gcryCipherHd;

    size_t index;
    size_t keyLength = gcry_cipher_get_algo_keylen(GCRY_CIPHER);
    size_t blkLength = gcry_cipher_get_algo_blklen(GCRY_CIPHER);
    char * txtBuffer = "123456789 abcdefghijklmnopqrstuvwzyz ABCDEFGHIJKLMNOPQRSTUVWZYZ";
    size_t txtLength = strlen(txtBuffer)+1; // string plus termination
    char * encBuffer = malloc(txtLength);
    char * outBuffer = malloc(txtLength);
    char * aesSymKey = "one test AES key"; // 16 bytes
    char * iniVector = "a test ini value"; // 16 bytes

    gcryError = gcry_cipher_open(
        &gcryCipherHd, // gcry_cipher_hd_t *
        GCRY_CIPHER,   // int
        GCRY_C_MODE,   // int
        0);            // unsigned int
    if (gcryError)
    {
        printf("gcry_cipher_open failed:  %s/%s\n",
        gcry_strsource(gcryError),
        gcry_strerror(gcryError));
        return;
    }
    printf("gcry_cipher_open    worked\n");

    gcryError = gcry_cipher_setkey(gcryCipherHd, aesSymKey, keyLength);
    if (gcryError)
    {
        printf("gcry_cipher_setkey failed:  %s/%s\n",
        gcry_strsource(gcryError),
        gcry_strerror(gcryError));
        return;
    }
    printf("gcry_cipher_setkey  worked\n");
    gcryError = gcry_cipher_setiv(gcryCipherHd, iniVector, blkLength);
    if (gcryError)
    {
        printf("gcry_cipher_setiv failed:  %s/%s\n",
        gcry_strsource(gcryError),
        gcry_strerror(gcryError));
        return;
    }
    printf("gcry_cipher_setiv   worked\n");
    gcryError = gcry_cipher_encrypt(gcryCipherHd, // gcry_cipher_hd_t
                    encBuffer,    // void *
                    txtLength,    // size_t
                    txtBuffer,    // const void *
                    txtLength );   // size_t

    if (gcryError)
    {
        printf("gcry_cipher_encrypt failed:  %s/%s\n",
        gcry_strsource(gcryError),
        gcry_strerror(gcryError));
        return;
    }
    printf("gcry_cipher_encrypt worked\n");
    gcryError = gcry_cipher_setiv(gcryCipherHd, iniVector, blkLength);
    if (gcryError)
    {
        printf("gcry_cipher_setiv failed:  %s/%s\n",
        gcry_strsource(gcryError),
        gcry_strerror(gcryError));
        return;
    }

    printf("gcry_cipher_setiv   worked\n");

    gcryError = gcry_cipher_decrypt(
        gcryCipherHd, // gcry_cipher_hd_t
        outBuffer,    // void *
        txtLength,    // size_t
        encBuffer,    // const void *
        txtLength);   // size_t
    if (gcryError)
    {
        printf("gcry_cipher_decrypt failed:  %s/%s\n",
        gcry_strsource(gcryError),
        gcry_strerror(gcryError));
        return;
    }
    printf("gcry_cipher_decrypt worked\n");

    printf("keyLength = %zu\n", keyLength);
    printf("blkLength = %zu\n", blkLength);
    printf("txtLength = %zu\n", txtLength);
    printf("aesSymKey = %s\n", aesSymKey);
    printf("iniVector = %s\n", iniVector);
    printf("txtBuffer = %s\n", txtBuffer);

    printf("encBuffer = ");
    for (index = 0; index<(strlen(txtBuffer)+1) index++)
    printf("%02X", (unsigned char)encBuffer[index]);
    printf("\n");

    printf("outBuffer = %s\n", outBuffer);

    // clean up after ourselves
    gcry_cipher_close(gcryCipherHd);
    free(encBuffer);
    free(outBuffer);
}

This ample code works. but i would really like to know which cipher and cipher mode is used by QUIC version 0xfaceb00 and what are these aesSymKey , iniVector.

Kindly ignore my limited knowledge .

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by grahamb
close date 2019-05-08 12:12:52.094001

Comments

This doesn't seem to be a Wireshark question, so is off-topic for this site.

grahamb gravatar imagegrahamb ( 2019-05-08 12:12:45 +0000 )edit

oh sorry. Do you know any forums on this topic ?? Thanks in advance

Crazy_Bot1711 gravatar imageCrazy_Bot1711 ( 2019-05-09 06:26:09 +0000 )edit