Commit f1f35bd407
Unsigned
Layout: unified · split
content/blog/2018-11-28-aes-encryption.org +45 −44
| @@ -6,15 +6,15 @@ | |||
| 6 | * Basic AES | 6 | * Basic AES |
| 7 | 7 | ||
| 8 | If you're not familiar with encryption techniques, [[https://en.wikipedia.org/wiki/Advanced_Encryption_Standard][AES]] is the *Advanced | 8 | If you're not familiar with encryption techniques, [[https://en.wikipedia.org/wiki/Advanced_Encryption_Standard][AES]] is the *Advanced |
| 9 | Encryption Standard*. This specification was established by the National | 9 | Encryption Standard*. The National Institute of Standards and Technology |
| 10 | Institute of Standards and Technology, sub-selected from the Rijndael family of | 10 | established this specification, sub-selected from the Rijndael family of ciphers |
| 11 | ciphers (128, 192, and 256 bits) in 2001. Furthering its popularity and status, | 11 | (128, 192, and 256 bits) in 2001. Furthering its popularity and status, the US |
| 12 | the US government chose AES as their default encryption method for top-secret | 12 | government chose AES as their default encryption method for top-secret data, |
| 13 | data, removing the previous standard which had been in place since 1977. | 13 | removing the previous standard which had been in place since 1977. |
| 14 | 14 | ||
| 15 | AES has proven to be an extremely safe encryption method, with 7-round and | 15 | AES has proven to be a safe encryption method, with 7-round and 8-round attacks |
| 16 | 8-round attacks making no material improvements since the release of this | 16 | making no material improvements since the release of this encryption standard |
| 17 | encryption standard almost two decades ago. | 17 | almost two decades ago. |
| 18 | 18 | ||
| 19 | #+begin_quote | 19 | #+begin_quote |
| 20 | Though many papers have been published on the cryptanalysis of AES, the fastest | 20 | Though many papers have been published on the cryptanalysis of AES, the fastest |
| @@ -26,12 +26,13 @@ slightly more powerful than those proposed 10 years ago [23,24]. | |||
| 26 | 26 | ||
| 27 | * How Secure is AES? | 27 | * How Secure is AES? |
| 28 | 28 | ||
| 29 | In theory, AES-256 is non-crackable due to the massive number of combinations | 29 | In theory, AES-256 (AES using a 256-bit key) is non-crackable due to the massive |
| 30 | that can be produced. However, AES-128 is no longer recommended as a viable | 30 | number of combinations that can the encryption process can produce. However, |
| 31 | implementation to protect important data. | 31 | AES-128 is no longer recommended as a viable implementation to protect important |
| 32 | data due the 128-bit key's short length. | ||
| 32 | 33 | ||
| 33 | A semi-short [[http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html][comic strip]] from Moserware quickly explains AES for the public to | 34 | A semi-short [[http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html][comic strip]] from Moserware quickly explains AES for the public to |
| 34 | understand. Basically AES encrypts the data by obscuring the relationship | 35 | understand. Basically, AES encrypts the data by obscuring the relationship |
| 35 | between the data and the encrypted data. Additionally, this method spreads the | 36 | between the data and the encrypted data. Additionally, this method spreads the |
| 36 | message out. Lastly, the key produced by AES is the secret to decrypting it. | 37 | message out. Lastly, the key produced by AES is the secret to decrypting it. |
| 37 | Someone may know the method of AES, but without the key, they are powerless. | 38 | Someone may know the method of AES, but without the key, they are powerless. |
| @@ -40,8 +41,8 @@ To obscure and spread the data out, AES creates a substitution-permutation | |||
| 40 | network. Wikipedia has a wonderful [[https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/SubstitutionPermutationNetwork2.png/468px-SubstitutionPermutationNetwork2.png][example of an SP network]] available. This | 41 | network. Wikipedia has a wonderful [[https://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/SubstitutionPermutationNetwork2.png/468px-SubstitutionPermutationNetwork2.png][example of an SP network]] available. This |
| 41 | network sends the data through a set of S boxes (using the unique key) to | 42 | network sends the data through a set of S boxes (using the unique key) to |
| 42 | substitute the bits with another block of bits. Then, a P box will permutate, or | 43 | substitute the bits with another block of bits. Then, a P box will permutate, or |
| 43 | rearrange, the bits. This is done over and over, with the key being derived from | 44 | rearrange, the bits. This is performed numerous times, with the last round |
| 44 | the last round. For AES, the key size specifies the number of transformation | 45 | deriving the key. For AES, the key size specifies the number of transformation |
| 45 | rounds: 10, 12, and 14 rounds for 128-bit, 192-bit, and 256-bit keys, | 46 | rounds: 10, 12, and 14 rounds for 128-bit, 192-bit, and 256-bit keys, |
| 46 | respectively. | 47 | respectively. |
| 47 | 48 | ||
| @@ -49,13 +50,13 @@ respectively. | |||
| 49 | 50 | ||
| 50 | 1. *KeyExpansion*: Using [[https://en.m.wikipedia.org/wiki/Advanced_Encryption_Standard][Rijndael's key schedule]], the keys are dynamically | 51 | 1. *KeyExpansion*: Using [[https://en.m.wikipedia.org/wiki/Advanced_Encryption_Standard][Rijndael's key schedule]], the keys are dynamically |
| 51 | generated. | 52 | generated. |
| 52 | 2. *AddRoundKey*: Each byte of the data is combined with this key using bitwise | 53 | 2. *AddRoundKey*: The process combines each byte of the data with the generated |
| 53 | xor. | 54 | key(s) using bitwise xor. |
| 54 | 3. *SubBytes*: This is followed by the substitution of each byte of data. | 55 | 3. *SubBytes*: Next, the process substitutes each byte of data. |
| 55 | 4. *ShiftRows*: Then, the final three rows are shifted a certain number of | 56 | 4. *ShiftRows*: Then, the process shifts the final three rows a specific number |
| 56 | steps, dictated by the cipher. | 57 | of steps, dictated by the cipher. |
| 57 | 5. *MixColumns*: After the rows have been shifted, the columns are mixed and | 58 | 5. *MixColumns*: Finally, the process mixes and combines the columns into the |
| 58 | combined. | 59 | final data for this round of processing. |
| 59 | 60 | ||
| 60 | This process does not necessarily stop after one full round. Steps 2 through 5 | 61 | This process does not necessarily stop after one full round. Steps 2 through 5 |
| 61 | will repeat for the number of rounds specified by the key. However, the final | 62 | will repeat for the number of rounds specified by the key. However, the final |
| @@ -66,42 +67,42 @@ weakness). | |||
| 66 | 67 | ||
| 67 | According to research done by Bogdanov et al., it would take billions of years | 68 | According to research done by Bogdanov et al., it would take billions of years |
| 68 | to brute force a 126-bit key with current hardware. Additionally, this brute | 69 | to brute force a 126-bit key with current hardware. Additionally, this brute |
| 69 | force attack would require storing 2^{88} bits of data! However, there are a few | 70 | force attack would require storing 2^{88} bits of data! However, people have |
| 70 | different attacks that have been used to show vulnerabilities with the use of | 71 | shown different attacks displaying vulnerabilities with the use of this |
| 71 | this technology. Side-channel attacks use inadvertent leaks of data from the | 72 | technology. Side-channel attacks use inadvertent leaks of data from the hardware |
| 72 | hardware or software, which can allow attackers to obtain the key or run | 73 | or software, which can allow attackers to obtain the key or run programs on a |
| 73 | programs on a user's hardware. | 74 | user's hardware. |
| 74 | 75 | ||
| 75 | Please note that this is not something you should run out and try to implement | 76 | Please note that this is not something you should run out and try to implement |
| 76 | in your =Hello, World!= app after only a few hours of research. While AES | 77 | in your =Hello, World!= application after only hours of research. While AES |
| 77 | (basically all encryption methods) is extremely efficient in what it does, it | 78 | (basically all encryption methods) is efficient in what it does, it takes a lot |
| 78 | takes a lot of time and patience to understand. If you're looking for something | 79 | of time and patience to understand. If you're looking for something which |
| 79 | which currently implements AES, check out the [[https://www.bouncycastle.org/documentation.html][Legion of the Bouncy Castle]] for | 80 | currently implements AES, check out the [[https://www.bouncycastle.org/documentation.html][Legion of the Bouncy Castle]] for Java |
| 80 | Java implementations of cryptographic algorithms. | 81 | implementations of cryptographic algorithms. |
| 81 | 82 | ||
| 82 | * Why Does Encryption Matter? | 83 | * Why Does Encryption Matter? |
| 83 | 84 | ||
| 84 | There are limitless reasons to enable encryption at-rest or in-transit for | 85 | There are limitless reasons to enable encryption at-rest or in-transit for |
| 85 | various aspects of your digital life. You can research specific examples, such | 86 | aspects of your digital life. You can research specific examples, such as |
| 86 | as [[https://arstechnica.com/tech-policy/2018/12/australia-passes-new-law-to-thwart-strong-encryption/][Australia passes new law to thwart strong encryption]]. However, I will simply | 87 | [[https://arstechnica.com/tech-policy/2018/12/australia-passes-new-law-to-thwart-strong-encryption/][Australia passes new law to thwart strong encryption]]. However, I will simply |
| 87 | list a few basic reasons to always enable encryption, where feasible: | 88 | list basic reasons to always enable encryption, where feasible: |
| 88 | 89 | ||
| 89 | 1. Privacy is a human right and is recognized as a national right in some | 90 | 1. Privacy is a human right and some countries recognize it as a national right |
| 90 | countries (e.g., [[https://www.law.cornell.edu/wex/fourth_amendment][US Fourth Amendment]]). | 91 | (e.g., [[https://www.law.cornell.edu/wex/fourth_amendment][US Fourth Amendment]]). |
| 91 | 2. "Why not?" Encryption rarely affects performance or speed, so there's usually | 92 | 2. "Why not?" Encryption rarely affects performance or speed, so there's usually |
| 92 | not a reason to avoid it in the first place. | 93 | not a reason to avoid it in the first place. |
| 93 | 3. Your digital identity and activity (texts, emails, phone calls, online | 94 | 3. Your digital identity and activity (texts, emails, phone calls, online |
| 94 | accounts, etc.) are extremely valuable and can result in terrible | 95 | accounts, etc.) are valuable and can result in consequences, such as identity |
| 95 | consequences, such as identity theft, if leaked to other parties. Encrypting | 96 | theft, if leaked to other parties. Encrypting this data prevents such leaks |
| 96 | this data prevents such leaks from ruining lives. | 97 | from ruining lives. |
| 97 | 4. Wiping or factory-resetting does not actually wipe all data from the storage | 98 | 4. Wiping or factory-resetting does not actually wipe all data from the storage |
| 98 | device. There are methods to read data from the physical disks/boards inside | 99 | device. There are methods to read data from the physical disks/boards inside |
| 99 | devices. | 100 | devices. |
| 100 | 5. Corporations, governments, and other nefarious groups/individuals are | 101 | 5. Corporations, governments, and other groups or individuals are actively |
| 101 | actively looking for ways to collect personal information about anyone they | 102 | looking for ways to collect personal information about anyone they can. If |
| 102 | can. If someone's data is unencrypted, that person may become a target due to | 103 | someone's data is not encrypted, that person may become a target due to the |
| 103 | the ease of data collection. | 104 | ease of data collection. |
| 104 | 105 | ||
| 105 | *Read More:* | 106 | * Read More |
| 106 | 107 | ||
| 107 | - [[http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197.pdf][Federal Information Processing Standards Publication 197]] | 108 | - [[http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197.pdf][Federal Information Processing Standards Publication 197]] |
content/blog/2018-11-28-cpp-compiler.org +24 −22
| @@ -8,10 +8,10 @@ | |||
| 8 | [[https://en.wikipedia.org/wiki/C%2B%2B][C++]] is a general-purpose programming language with object-oriented, generic, and | 8 | [[https://en.wikipedia.org/wiki/C%2B%2B][C++]] is a general-purpose programming language with object-oriented, generic, and |
| 9 | functional features in addition to facilities for low-level memory manipulation. | 9 | functional features in addition to facilities for low-level memory manipulation. |
| 10 | 10 | ||
| 11 | The source code, shown in the snippet below, must be compiled before it can be | 11 | A developer must compile source code, such as the example shown in the snippet |
| 12 | executed. There are many steps and intricacies to the compilation process, and | 12 | below, before they can execute the compiled program. There are numerous steps |
| 13 | this post was a personal exercise to learn and remember as much information as I | 13 | and intricacies to the compilation process, and this post was a personal |
| 14 | can. | 14 | exercise to learn and remember as much information as I can. |
| 15 | 15 | ||
| 16 | #+begin_src cpp | 16 | #+begin_src cpp |
| 17 | #include <iostream> | 17 | #include <iostream> |
| @@ -36,9 +36,10 @@ is not the only compiled language. Check out [[https://en.wikipedia.org/wiki/Com | |||
| 36 | languages]] for more examples of compiled languages. | 36 | languages]] for more examples of compiled languages. |
| 37 | 37 | ||
| 38 | I'll start with a wonderful, graphical way to conceptualize the C++ compiler. | 38 | I'll start with a wonderful, graphical way to conceptualize the C++ compiler. |
| 39 | View [[https://web.archive.org/web/20190419035048/http://faculty.cs.niu.edu/~mcmahon/CS241/Notes/compile.html][The C++ Compilation Process]] by Kurt MacMahon, an NIU professor, to see the | 39 | View [[https://web.archive.org/web/20190419035048/http://faculty.cs.niu.edu/~mcmahon/CS241/Notes/compile.html][The C++ Compilation Process]] by Kurt MacMahon, a Northern Illinois |
| 40 | graphic and an explanation. The goal of the compilation process is to take the | 40 | University (NIU) professor, to see the graphic and an explanation. The goal of |
| 41 | C++ code and produce a shared library, dynamic library, or an executable file. | 41 | the compilation process is to take the C++ code and produce a shared library, |
| 42 | dynamic library, or an executable file. | ||
| 42 | 43 | ||
| 43 | ** Compilation Phases | 44 | ** Compilation Phases |
| 44 | 45 | ||
| @@ -61,10 +62,11 @@ the expanded code. | |||
| 61 | 62 | ||
| 62 | *** Step 2 | 63 | *** Step 2 |
| 63 | 64 | ||
| 64 | After the code is expanded, the compiler comes into play. The compiler takes the | 65 | After the compiler expands the code, the compiler comes into play. The compiler |
| 65 | C++ code and converts this code into the assembly language, understood by the | 66 | takes the C++ code and converts this code into the assembly language, understood |
| 66 | platform. You can see this in action if you head over to the [[https://godbolt.org][GodBolt Compiler | 67 | by the platform. You can see this in action if you head over to the [[https://godbolt.org][GodBolt |
| 67 | Explorer]], which shows C++ being converted into assembly dynamically. | 68 | Compiler Explorer]], which shows the compiled converting C++ into assembly |
| 69 | dynamically. | ||
| 68 | 70 | ||
| 69 | For example, the =Hello, world!= code snippet above compiles into the following | 71 | For example, the =Hello, world!= code snippet above compiles into the following |
| 70 | assembly code: | 72 | assembly code: |
| @@ -113,17 +115,17 @@ _GLOBAL__sub_I_main: | |||
| 113 | 115 | ||
| 114 | *** Step 3 | 116 | *** Step 3 |
| 115 | 117 | ||
| 116 | Third, the assembly code generated by the compiler is assembled into the object | 118 | Third, the compiled assembles the assembly code into the object code for the |
| 117 | code for the platform. Essentially, this is when the compiler takes the assembly | 119 | platform. Essentially, this is when the compiler takes the assembly code and |
| 118 | code and assembles it into machine code in a binary format. After researching | 120 | assembles it into machine code in a binary format. After researching this |
| 119 | this online, I figured out that a lot of compilers will allow you to stop | 121 | online, I figured out that a lot of compilers will allow you to stop compilation |
| 120 | compilation at this step. This would be useful for compiling each source code | 122 | at this step. This would be useful for compiling each source code file |
| 121 | file separately. This saves time later if a single file changes; only that file | 123 | separately. This saves time later if a single file changes, since the developer |
| 122 | needs to be recompiled. | 124 | will only need to re-compile single file. |
| 123 | 125 | ||
| 124 | *** Step 4 | 126 | *** Step 4 |
| 125 | 127 | ||
| 126 | Finally, the object code file generated by the assembler is linked together with | 128 | Finally, the compiler links the object code file generated by the assembler |
| 127 | the object code files for any library functions used to produce a shared | 129 | together with the object code files for any library functions used to produce a |
| 128 | library, dynamic library, or an executable file. It replaces all references to | 130 | shared library, dynamic library, or an executable file. It replaces all |
| 129 | undefined symbols with the correct addresses. | 131 | references to undefined symbols with the correct addresses. |