Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to decrypt this example #235

Open
tttony opened this issue Jan 15, 2025 · 2 comments
Open

Fails to decrypt this example #235

tttony opened this issue Jan 15, 2025 · 2 comments

Comments

@tttony
Copy link

tttony commented Jan 15, 2025

Version: commit 2385675
VS 2017
Windows 7 x64 (for testing)

The decryption result in bytes/string is:

46 a9 dc 7b 96 19 b8 61 8c df a2 1c 94 c7 8e c1 54 68 69 73 20  F©Ü{–.¸aŒß¢.”ÇŽÁThis 
69 73 20 70 61 74 72 69 63 6b 21 54 68 69 73 20 69 73 20 70 61  is patrick!This is pa
74 72 69 63 6b 21 54 68 69 73 20 69 73 20 70 61 74 72 69 63 6b  trick!This is patrick
21 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ! 

The expected string result should be:

This is patrick!This is patrick!This is patrick!This is patrick!

Here is the code example:

#include <stdio.h>

#define CBC 1
#define CTR 1
#define ECB 1

#include <string.h>

#include "../aes.h"

int main()
{
    struct AES_ctx ctx;

    char input[] = "This is patrick!This is patrick!This is patrick!This is patrick!";
    size_t inlen = strlen(input);

    char copyin[256] = { 0 };
    strcpy(copyin, input);

    char key[] = "gmufm6nfjcylr4pf";
    char iv[] = "ThisFuckinIvHere";

    AES_init_ctx_iv(&ctx, key, iv);
    AES_CBC_encrypt_buffer(&ctx, copyin, inlen);
    AES_CBC_decrypt_buffer(&ctx, copyin, inlen);

    printf("CBC decrypt: ");
    if (0 == memcmp(input, copyin, inlen)) {
        printf("SUCCESS!\n");
        return 0;
    }
    printf("FAILURE!\n");
    return 1;
}
@waelmahrous
Copy link

waelmahrous commented Jan 23, 2025

If not mistaken, I believe you have to reinitialise the context before trying to decrypt :)

@tttony
Copy link
Author

tttony commented Jan 23, 2025

Oops! You right, now it works! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants