Giter VIP home page Giter VIP logo

halloweeks / aes-128-ecb Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 78 KB

This GitHub repository houses a standard AES-128 ECB (Electronic Codebook) encryption algorithm implemented in the C programming language. AES-128 is a widely recognized encryption standard known for its security and efficiency.

License: MIT License

C 100.00%
aes-128 aes-128-ecb aes-ecb aes-in-c cryptography ecb encryption security aes-implement-in-c

aes-128-ecb's Introduction

Overview

This GitHub repository contains a standard implementation of the Advanced Encryption Standard (AES) with a focus on AES-128 ECB (Electronic Codebook) encryption. AES-128 is a widely adopted encryption standard known for its security and efficiency.

Features

  • AES-128 ECB: This implementation adheres to the AES-128 ECB encryption mode, which encrypts individual 16-byte blocks of data independently.

  • Fixed Block Size: The algorithm enforces a fixed block size of 16 bytes, and it does not support padding. Input data must be exactly 16 bytes in length for each block.

  • Compatibility: Data encrypted using this standard AES-128 ECB algorithm can be decrypted using any compliant AES-128 ECB decryption implementation.

Usage

To utilize this standard AES-128 ECB implementation, follow the instructions provided below:

Including "AES_128_ECB.h" Header

Before utilizing the AES encryption and decryption functions, ensure that you've included the "AES_128_ECB.h" header in your code. This header provides access to the AES functionality.

#include "AES_128_ECB.h"

AES Context Initialization

To perform AES encryption and decryption, you must initialize an AES context. This context serves as a container for maintaining the encryption and decryption state.

AES_CTX ctx;

Initialize Encryption

To perform encryption, initialize the AES context and provide the encryption key.

AES_EncryptInit(&ctx, key);

Encryption Function

The AES encryption function allows you to encrypt a blocks of data, and this implementation does not support padding. Ensure that you provide data blocks of precisely 16 bytes.

AES_Encrypt(&ctx, plaintext, plaintext_length, ciphertext);

Initialize Decryption

To perform decryption, initialize the AES context with the same key used for encryption.

AES_DecryptInit(&ctx, key);

Decryption Function

The AES decryption function allows you to decrypt a blocks of data, and this implementation does not support padding. Ensure that you provide ciphertext blocks of precisely 16 bytes.

AES_Decrypt(&ctx, ciphertext, ciphertext_length, plaintext);

Encryption and Decryption Function Completion

After you have finished using the AES encryption and decryption functions and no longer require the AES context, it's essential to clear sensitive information from memory. Use the following function to achieve this:

AES_CTX_Free(&ctx);

Example Code (main.c)

Here's an example code snippet in C for using this standard AES-128 ECB implementation:

#include <stdio.h>
#include "AES_128_ECB.h"

// Function to print the title and hexadecimal representation of data
void output(const char *title, const unsigned char *data, unsigned int size) {
    printf("%s", title);
    for (unsigned int index = 0; index < size; index++) {
        printf("%02X", data[index]);
    }
    printf("\n");
}

int main(int argc, const char *argv[]) {
    // AES-128 key (16 bytes)
    unsigned char key[AES_KEY_SIZE] = {
        0x49, 0x2F, 0xA8, 0x1E, 0xD7, 0x82, 0x4C, 0x93,
        0x36, 0x7B, 0xC1, 0xF8, 0xA0, 0xE5, 0x1A, 0x5D
    };

    // Data block to be encrypted (16 bytes)
    unsigned char data[AES_BLOCK_SIZE] = {
        0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20,
        0x61, 0x6E, 0x20, 0x64, 0x61, 0x74, 0x61, 0x21
    };

    // Print original data
    output("ori: 0x", data, 16);

    // Initialize AES context
    AES_CTX ctx;

    // Initialize encryption with the provided key
    AES_EncryptInit(&ctx, key);

    // Perform encryption
    AES_Encrypt(&ctx, data, 16, data);

    // Print encrypted data
    output("enc: 0x", data, 16);

    // Initialize decryption with the same key
    AES_DecryptInit(&ctx, key);

    // Perform decryption
    AES_Decrypt(&ctx, data, 16, data);

    // Print decrypted data
    output("dec: 0x", data, 16);

    // Clean up: zero out the round key array for security purposes
    AES_CTX_Free(&ctx);

    return 0;
}

Contributions

Contributions and feedback are welcome! If you find issues or have ideas for improvements, please open an issue or submit a pull request.

License

This standard AES-128 ECB implementation is provided under the MIT License.

aes-128-ecb's People

Contributors

halloweeks avatar

Watchers

 avatar

Forkers

gmh5225

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.