Giter Site home page Giter Site logo

openluopworld / aes_128 Goto Github PK

View Code? Open in Web Editor NEW
115.0 13.0 47.0 69 KB

Implementation of AES-128 in pure C. No modes are given. Only one block of encryption and decryption is given here.

Home Page: http://www.luopeng.site/aes_128/

License: MIT License

C 99.82% Makefile 0.18%
aes encryption block-cipher crypto c cryptography

aes_128's Introduction

AES-128

Build Status Coverity Scan Build Status

C implementation of AES-128. No modes are given. This code has been tested with GCC 4.8.4 and Valgrind-3.11.0 on Intel-i5-3230.

How to read

Reading of the paper AES Proposal: Rijndael first is recommended. If you care more about the implementation, Chapter 4 is enough.

  • Reference implementation: ./aes.c
    • This should be read first. Since it is the reference implementation.
  • Full unroll implementation: ./unroll/aes.c
    • The full unroll impelementation is easy to understand if you have read the reference one.
  • Look up table implementation: ./lut/aes.c
    • Lut may be something difficult. But it is widely used in softwares.
    • gen_dec_key_table.c, gen_enc_table.c and gen_dec_table.c are utils.
    • This code suppose the mechine is little-endian.
  • If you still have interest, the advanced implementations with SIMD instructions or hardware instructions can be found in some famous projects.

Usage

Interface

/**
 * @purpose:            Key schedule for AES-128
 * @par[in]key:         16 bytes of master keys
 * @par[out]roundkeys:  176 bytes of round keys
 */
void aes_key_schedule_128(const uint8_t *key, uint8_t *roundkeys);

/**
 * @purpose:            Encryption. The length of plain and cipher should be one block (16 bytes).
 *                      The plaintext and ciphertext may point to the same memory
 * @par[in]roundkeys:   round keys
 * @par[in]plaintext:   plain text
 * @par[out]ciphertext: cipher text
 */
void aes_encrypt_128(const uint8_t *roundkeys, const uint8_t *plaintext, uint8_t *ciphertext);

/**
 * @purpose:            Decryption. The length of plain and cipher should be one block (16 bytes).
 *                      The ciphertext and plaintext may point to the same memory
 * @par[in]roundkeys:   round keys
 * @par[in]ciphertext:  cipher text
 * @par[out]plaintext:  plain text
 */
void aes_decrypt_128(const uint8_t *roundkeys, const uint8_t *ciphertext, uint8_t *plaintext);

Compile

make

Dependencies

  • The code is written in standard C
  • No dependencies of other libraries

Contributing

If there is anything wrong or if you have any question, just make an issue or email me.

Todo

'Todo' may always be 'To do', so I do not like this word, but...

License

Copyright (c) 2017 LuoPeng

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

aes_128's People

Contributors

margen67 avatar openluopworld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aes_128's Issues

再次感谢您惊人的代码, 巧妙地实现方式, 但是还有个解密的问题(逆列混合运算)

尊敬的luopeng先生:
您好, 又是我, 感谢您上次的耐心教导, 让我明白了为什么化简为这个样子, 但是我再看您关于解密的代码时, 有三个变量u v t, 并且用这三个变量计算出接近明文的过程让我又再度产生和之前一样的疑惑, 所以还得向您请教, 希望得到您的再次回复, 再次感谢您, 祝愿您工作顺利, 生活美满, 完事如意.
image

能否出个aes_256的查表版本

大神你好,我运行了一下您的ace_128查表版本,和jdk自带的实现对比了一下,确实效率很高。
想问下能否出个aes_256的查表版本?
aes_128加密强度已经足够,但如果同时有个aes_256的话会更完备一些。

感谢您惊人的代码, 但是还得教您关于您在GitHub上AES的一段代码问题

尊敬的luopeng先生您好:
我在看您关于AES代码实现中的9轮加密中的列混合无论如何都看不懂, 也就是如下代码, 您实现的方式是异常巧妙地, 可是我即使知道结果是对的, 但无法知道为什么您这么做, 可否得到您的回复, 如果您愿意分享的话, 将万分感谢, 谢谢您的代码, 让我懂得了很多.
image

[INVALID] Windows binary

Dear Luo Peng,
Could you be so kind to generate .exe for the rest of us who are mere Windows users w/o compiler?

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.