DEV Community

Cover image for From Zero To Crypto-Hero - (Week 1)
Luftie The Anonymous
Luftie The Anonymous

Posted on

From Zero To Crypto-Hero - (Week 1)

Hello Dev.to Community !

This time I will share with you what I did in a full week 1 of my transition from zero to crypto-hero ? And as I promised, every sunday I will post a weekly-summary of my effort.

Are you ready ?

Let's go !

1 Week Overview

Surprisingly, I haven't done much this week in terms of cryptography development. I had a bit of tiny errands this week, that took my time and energy. One of them you can see here: One of the Errand-video

I would not say that my efforts were low because of lack of time, but rather because of cognitive overload I would name it.

What have I done ?

I have practiced modular mathematics together with turning the binary into a polynomial and practiced modular reduction of an polynomial, that is actually needed for AES on the substitution-layer level, as in the substitution table in order to get the value we have 2 approaches.

To those who do not know in short AES is an symmetric block-cipher that is built in a following way.

input                      original-key
|                          |
|                          |
|                          |
v                          V
key addition    <---   nth round-key
|
|
|
v
substitution layer
|
|
v
shift-row layer
|
|
v
mix-column
|
|
v
add-round-key
Enter fullscreen mode Exit fullscreen mode

Not comming much into details this process above of encryption is repeated depending on the key length in AES, which is:
For 128 bits: 10 rounds / 11 round-keys
For 192 bits: 12 rounds / 13 round-keys
For 256 bits: 14 rounds / 15 round-keys

Because key addition is done on the beginning before actual encryption and at the end as the last round is finished, thus there are round-quantity + 1 amount of keys.

And for the substitution-layer we get the value for the input either by turning the byte value to a position in a look-up table or we will turn the byte value to polynomial and find an inverse for this polynomial in GF(2^8), by usage of Extended Euclidian Algorithm with irreducible polynomial of the GF(2^8), such that:

input-polynomial * input-polynomial-inverse = 1 mod field-irreducible-polynomial.
Enter fullscreen mode Exit fullscreen mode

I have been relearning DES and AES cipher, whereas I spent about 2 days on AES, because I could not understand fully it's key-schedule workflow.

I have explored the bit manipulation key-words in TS like left-shift, right-shift or that we can xor without turning into binary, what I actually did in my implementation for OTP πŸ˜…

I recapped all of my notes on cryptography from Christof Paar course.

I implemented decimal to hex value helper function, Euler's totient function and Extended Euclidian Algorithm to my crypto-library project in TS.

And here are couple things I inferred.

  1. My notes were purely theoretical and were mostly math-focused and for understanding concept instead of ready to implement the cipher in code. For instance I wanted to implement RSA, because it's quite simple math, that is rather math-focused than about bit shifting etc.

What I realized was that in order to get an p and q value, that would be prime-values, that are at least 2^512 bit long, I need to implement primality test from Miller-Rabin Primality Test or Little Fermat's Theorem, whereas Miller-Rabin is more efficient for large numbers than Little Fermat's approach. And I actually run into headache to understand how miller-rabin primality test works 😬

  1. I would need to recap the ciphers all from scratch by reading the book and focusing on implementation rather than understanding how it works.

Unexpected Approval and Plan Change

Additionally there came an unexpected surprise, I have written an article on this this week, however to recall it I got approved to participate in an ETHSilesia Hackathon. Where honestly I did not expected to approved.

And it kind of forced me to change my plans. Namely I decided to temporarily cease development of my crypto-library that I started and my plans to move all-in to cryptography and blockchain architecture. And focus purely on web3-focused matters together with the hackathon-preparation, sometimes such shit happens. And I will comeback to cryptography development all in, after the hackathon.

So that's it for this week, to every woman in programming and in the world, I wish you all the best, you're rocking !

Cheers and see you next week :D

Ps. if you found some mistake feel free to correct me in terms of AES explanation.

Top comments (0)