1
Fork 0
mirror of https://github.com/Steffo99/unimore-oop-2020-cleaver.git synced 2024-11-21 15:44:20 +00:00

Commit new example

This commit is contained in:
Steffo 2020-01-12 15:31:10 +01:00
parent a2cee61e78
commit d7890dce4b
4 changed files with 384 additions and 0 deletions

View file

@ -0,0 +1,295 @@
{{Infobox block cipher
| name = Advanced Encryption Standard{{break}}(Rijndael)
| image = AES-SubBytes.svg
| caption = The {{mono | SubBytes}} step, one of four stages in a round of AES
| designers = [[Vincent Rijmen]], [[Joan Daemen]]
| publish date = 1998
| derived from = [[Square (cipher)|Square]]
| derived to = [[Anubis (cipher)|Anubis]], [[Grand Cru (cipher)|Grand Cru]], [[Kalyna (cipher)|Kalyna]]
| related to =
| certification = [[Advanced Encryption Standard process|AES]] winner, [[CRYPTREC]], [[NESSIE]], [[National Security Agency|NSA]]
| key size = 128, 192 or 256 bits<ref name="keysize" group="note">Key sizes of 128, 160, 192, 224, and 256 bits are supported by the Rijndael algorithm, but only the 128, 192, and 256-bit key sizes are specified in the AES standard.</ref>
| block size = 128 bits<ref name="blocksize" group="note">Block sizes of 128, 160, 192, 224, and 256 bits are supported by the Rijndael algorithm for each key size, but only the 128-bit block size is specified in the AES standard.</ref>
| structure = [[Substitutionpermutation network]]
| rounds = 10, 12 or 14 (depending on key size)
| cryptanalysis = Attacks have been published that are computationally faster than a full [[brute-force attack]], though none as of 2013 are computationally feasible.<ref name="aesbc">{{cite web|url=http://research.microsoft.com/en-us/projects/cryptanalysis/aesbc.pdf|archiveurl=https://web.archive.org/web/20160306104007/http://research.microsoft.com/en-us/projects/cryptanalysis/aesbc.pdf|archivedate=March 6, 2016|title=Biclique Cryptanalysis of the Full AES|accessdate=May 1, 2019|url-status=dead|df=mdy-all}}</ref>
For AES-128, the key can be recovered with a computational complexity of 2<sup>126.1</sup> using the [[biclique attack]]. For biclique attacks on AES-192 and AES-256, the computational complexities of 2<sup>189.7</sup> and 2<sup>254.4</sup> respectively apply. [[Related-key attack]]s can break AES-192 and AES-256 with complexities 2<sup>176</sup> and 2<sup>99.5</sup> in both time and data, respectively.<ref name=relkey>Alex Biryukov and Dmitry Khovratovich, ''Related-key Cryptanalysis of the Full AES-192 and AES-256'', {{cite web |url=http://eprint.iacr.org/2009/317 |title=Archived copy |accessdate=2010-02-16 |url-status=live |archiveurl=https://web.archive.org/web/20090928014006/http://eprint.iacr.org/2009/317 |archivedate=2009-09-28 |at=Table 1}}</ref>
}}
The '''Advanced Encryption Standard''' ('''AES'''), also known by its original name '''Rijndael''' ({{IPA-nl|ˈrɛindaːl}}),<ref name="Rijndael-ammended.pdf" /> is a specification for the [[encryption]] of electronic data established by the U.S. [[National Institute of Standards and Technology]] (NIST) in 2001.<ref name="fips-197">{{cite web|url=http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197.pdf|title=Announcing the ADVANCED ENCRYPTION STANDARD (AES)|publisher=United States National Institute of Standards and Technology (NIST)|work=Federal Information Processing Standards Publication 197|date=November 26, 2001|accessdate=October 2, 2012|url-status=live|archiveurl=https://web.archive.org/web/20170312045558/http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197.pdf|archivedate=March 12, 2017}}</ref>
AES is a subset of the Rijndael [[block cipher]]<ref name="Rijndael-ammended.pdf">{{cite web |url=http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=1 |title=AES Proposal: Rijndael |last1=Daemen |first1=Joan |last2=Rijmen |first2=Vincent |date=March 9, 2003 |publisher=National Institute of Standards and Technology |page=1 |accessdate=21 February 2013 |url-status=live |archiveurl=https://web.archive.org/web/20130305143117/http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=1 |archivedate=5 March 2013 }}</ref> developed by two [[Belgium|Belgian]] cryptographers, [[Vincent Rijmen]] and [[Joan Daemen]], who submitted a proposal<ref name="Rijndaelv2">{{cite web|url=http://csrc.nist.gov/CryptoToolkit/aes/rijndael/Rijndael.pdf|url-status=dead|archiveurl=https://web.archive.org/web/20070203204845/https://csrc.nist.gov/CryptoToolkit/aes/rijndael/Rijndael.pdf|archivedate=February 3, 2007|title=AES Proposal: Rijndael|author=Joan Daemen and Vincent Rijmen|date=September 3, 1999}}</ref> to NIST during the [[Advanced Encryption Standard process|AES selection process]].<ref>{{Cite news |title=U.S. Selects a New Encryption Technique |author=John Schwartz |newspaper=New York Times |date=October 3, 2000 |url=https://www.nytimes.com/2000/10/03/business/technology-us-selects-a-new-encryption-technique.html |url-status=live |archiveurl=https://web.archive.org/web/20170328215407/http://www.nytimes.com/2000/10/03/business/technology-us-selects-a-new-encryption-technique.html |archivedate=March 28, 2017 }}</ref> Rijndael is a family of ciphers with different key and block sizes.
For AES, NIST selected three members of the Rijndael family, each with a block size of 128 bits, but three different key lengths: 128, 192 and 256 bits.
AES has been adopted by the [[Federal government of the United States|U.S. government]] and is now used worldwide. It supersedes the [[Data Encryption Standard]] (DES),<ref>{{cite news|url=http://www.findarticles.com/p/articles/mi_m0IKZ/is_3_107?pnum=2&opg=90984479 |title=NIST reports measurable success of Advanced Encryption Standard |work=Journal of Research of the National Institute of Standards and Technology |first=Harold B. |last=Westlund |date=2002 |url-status=dead |archiveurl=https://web.archive.org/web/20071103105501/http://findarticles.com/p/articles/mi_m0IKZ/is_3_107?pnum=2&opg=90984479 |archivedate=2007-11-03 }}</ref> which was published in 1977. The algorithm described by AES is a [[symmetric-key algorithm]], meaning the same key is used for both encrypting and decrypting the data.
In the United States, AES was announced by the NIST as U.S. [[Federal Information Processing Standard|FIPS]] PUB 197 (FIPS 197) on November 26, 2001.<ref name="fips-197" /> This announcement followed a five-year standardization process in which fifteen competing designs were presented and evaluated, before the Rijndael cipher was selected as the most suitable (see [[Advanced Encryption Standard process]] for more details).
AES became effective as a federal government standard on May 26, 2002, after approval by the [[United States Secretary of Commerce|Secretary of Commerce]]. AES is included in the [[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]] [[List of International Organization for Standardization standards, 18000-19999|18033-3]] standard. AES is available in many different encryption packages, and is the first (and only) publicly accessible [[cipher]] approved by the [[National Security Agency]] (NSA) for [[Classified information|top secret]] information when used in an NSA approved cryptographic module (see [[Advanced Encryption Standard#Security|Security of AES]], below).
== Definitive standards ==
The Advanced Encryption Standard (AES) is defined in each of:
* FIPS PUB 197: Advanced Encryption Standard (AES)<ref name="fips-197" />
* ISO/IEC 18033-3:: Block ciphers<ref name="ISO_IEC_AES">{{cite web
|url = http://www.iso.org/iso/home/store/catalogue_ics/catalogue_detail_ics.htm?csnumber=54531
|title = ISO/IEC 18033-3: Information technology Security techniques Encryption algorithms Part 3: Block ciphers
|url-status = live
|archiveurl = https://web.archive.org/web/20131203003348/http://www.iso.org/iso/home/store/catalogue_ics/catalogue_detail_ics.htm?csnumber=54531
|archivedate = 2013-12-03
}}</ref>
== Description of the ciphers ==
AES is based on a design principle known as a [[substitutionpermutation network]], and is efficient in both software and hardware.<ref>{{cite web |url=http://www.schneier.com/paper-twofish-final.pdf |title=The Twofish Team's Final Comments on AES Selection |display-authors=7 |author=Bruce Schneier |author2=John Kelsey |author3=Doug Whiting |author4=David Wagner |author5=Chris Hall |author6=Niels Ferguson |author7=Tadayoshi Kohno |author8=Mike Stay |date=May 2000 |url-status=live |archiveurl=https://web.archive.org/web/20100102041117/http://schneier.com/paper-twofish-final.pdf |archivedate=2010-01-02 }}</ref> Unlike its predecessor DES, AES does not use a [[Feistel network]]. AES is a variant of Rijndael which has a fixed [[block size (cryptography)|block size]] of 128 [[bit]]s, and a [[key size]] of 128, 192, or 256 bits. By contrast, Rijndael ''per se'' is specified with block and key sizes that may be any multiple of 32 bits, with a minimum of 128 and a maximum of 256 bits.
AES operates on a 4 × 4 [[column-major order]] array of bytes, termed the ''state''.<ref group="note">Large-block variants of Rijndael use an array with additional columns, but always four rows.</ref> Most AES calculations are done in a particular [[Finite field arithmetic|finite field]].
For instance, if there are 16 bytes, <math>b_0, b_1, ..., b_{15}</math>, these bytes are represented as this two-dimensional array:
::<math>
\begin{bmatrix}
b_0 & b_4 & b_8 & b_{12} \\
b_1 & b_5 & b_9 & b_{13} \\
b_2 & b_6 & b_{10} & b_{14} \\
b_3 & b_7 & b_{11} & b_{15}
\end{bmatrix}
</math>
The key size used for an AES cipher specifies the number of transformation rounds that convert the input, called the [[plaintext]], into the final output, called the [[ciphertext]]. The number of rounds are as follows:
* 10 rounds for 128-bit keys.
* 12 rounds for 192-bit keys.
* 14 rounds for 256-bit keys.
Each round consists of several processing steps, including one that depends on the encryption key itself. A set of reverse rounds are applied to transform ciphertext back into the original plaintext using the same encryption key.
=== High-level description of the algorithm ===
# {{mono | KeyExpansion}}—round keys are derived from the cipher key using [[Rijndael key schedule|Rijndael's key schedule]]. AES requires a separate 128-bit round key block for each round plus one more.
# Initial round key addition:
## {{mono | AddRoundKey}}—each byte of the state is combined with a byte of the round key using [[bitwise xor]].
# 9, 11 or 13 rounds:
## {{mono | SubBytes}}—a [[linear map|non-linear]] substitution step where each byte is replaced with another according to a [[Rijndael S-box|lookup table]].
## {{mono | ShiftRows}}—a transposition step where the last three rows of the state are shifted cyclically a certain number of steps.
## {{mono | MixColumns}}—a linear mixing operation which operates on the columns of the state, combining the four bytes in each column.
## {{mono | AddRoundKey}}
# Final round (making 10, 12 or 14 rounds in total):
## {{mono | SubBytes}}
## {{mono | ShiftRows}}
## {{mono | AddRoundKey}}
=== The {{mono | SubBytes}} step ===
{{Main|Rijndael S-box}}
[[Image:AES-SubBytes.svg|right|320px|thumbnail|In the {{mono | SubBytes}} step, each byte in the state is replaced with its entry in a fixed 8-bit lookup table, ''S''; ''b<sub>ij</sub>'' = ''S(a<sub>ij</sub>)''.]]
In the {{mono | SubBytes}} step, each byte <math>a_{i,j}</math> in the ''state'' array is replaced with a {{mono | SubByte}} <math>S(a_{i,j})</math> using an 8-bit [[substitution box]]. This operation provides the non-linearity in the [[cipher]]. The S-box used is derived from the [[multiplicative inverse]] over {{math|[[Finite field|GF]](2<sup>8</sup>)}}, known to have good non-linearity properties. To avoid attacks based on simple algebraic properties, the S-box is constructed by combining the inverse function with an invertible [[affine transformation]]. The S-box is also chosen to avoid any fixed points (and so is a [[derangement]]), i.e., <math> S(a_{i,j}) \neq a_{i,j} </math>, and also any opposite fixed points, i.e., <math> S(a_{i,j}) \oplus a_{i,j} \neq \text{FF}_{16} </math>.
While performing the decryption, the {{mono | InvSubBytes}} step (the inverse of {{mono | SubBytes}}) is used, which requires first taking the inverse of the affine transformation and then finding the multiplicative inverse.
=== The {{mono | ShiftRows}} step ===
[[Image:AES-ShiftRows.svg|right|320px|thumbnail|In the {{mono | ShiftRows}} step, bytes in each row of the state are shifted cyclically to the left. The number of places each byte is shifted differs for each row.]]
The {{mono | ShiftRows}} step operates on the rows of the state; it cyclically shifts the bytes in each row by a certain [[Offset (computer science)|offset]]. For AES, the first row is left unchanged. Each byte of the second row is shifted one to the left. Similarly, the third and fourth rows are shifted by offsets of two and three respectively.<ref group="note">Rijndael variants with a larger block size have slightly different offsets. For blocks of sizes 128 bits and 192 bits, the shifting pattern is the same. Row <math>n</math> is shifted left circular by <math>n-1</math> bytes. For a 256-bit block, the first row is unchanged and the shifting for the second, third and fourth row is 1 byte, 3 bytes and 4 bytes respectively—this change only applies for the Rijndael cipher when used with a 256-bit block, as AES does not use 256-bit blocks.</ref> In this way, each column of the output state of the {{mono | ShiftRows}} step is composed of bytes from each column of the input state. The importance of this step is to avoid the columns being encrypted independently, in which case AES degenerates into four independent block ciphers.
=== The {{mono | MixColumns}} step ===
{{main|Rijndael MixColumns}}
[[Image:AES-MixColumns.svg|right|320px|thumbnail|In the {{mono | MixColumns}} step, each column of the state is multiplied with a fixed polynomial <math>c(x)</math>.]]
In the {{mono | MixColumns}} step, the four bytes of each column of the state are combined using an invertible [[linear transformation]]. The {{mono | MixColumns}} function takes four bytes as input and outputs four bytes, where each input byte affects all four output bytes. Together with {{mono | ShiftRows}}, {{mono | MixColumns}} provides [[diffusion (cryptography)|diffusion]] in the cipher.
During this operation, each column is transformed using a fixed matrix (matrix left-multiplied by column gives new value of column in the state):
::<math>
\begin{bmatrix}
b_{0,j} \\ b_{1,j} \\ b_{2,j} \\ b_{3,j}
\end{bmatrix} = \begin{bmatrix}
2 & 3 & 1 & 1 \\
1 & 2 & 3 & 1 \\
1 & 1 & 2 & 3 \\
3 & 1 & 1 & 2
\end{bmatrix} \begin{bmatrix}
a_{0,j} \\ a_{1,j} \\ a_{2,j} \\ a_{3,j}
\end{bmatrix}
\qquad 0 \le j \le 3
</math>
Matrix multiplication is composed of multiplication and addition of the entries. Entries are 8-bit bytes treated as coefficients of polynomial of order <math>x^7</math>. Addition is simply XOR. Multiplication is modulo irreducible polynomial <math>x^8+x^4+x^3+x+1</math>. If processed bit by bit, then, after shifting, a conditional [[Exclusive or|XOR]] with 1B<sub>16</sub> should be performed if the shifted value is larger than FF<sub>16</sub> (overflow must be corrected by subtraction of generating polynomial). These are special cases of the usual multiplication in <math>\operatorname{GF}(2^8)</math>.
In more general sense, each column is treated as a polynomial over <math>\operatorname{GF}(2^8)</math> and is then multiplied modulo <math>{01}_{16} \cdot z^4+{01}_{16}</math> with a fixed polynomial <math>c(z) = {03}_{16} \cdot z^3 + {01}_{16} \cdot z^2 +{01}_{16} \cdot z + {02}_{16}</math>. The coefficients are displayed in their [[hexadecimal]] equivalent of the binary representation of bit polynomials from <math>\operatorname{GF}(2)[x]</math>. The {{mono | MixColumns}} step can also be viewed as a multiplication by the shown particular [[MDS matrix]] in the [[finite field]] <math>\operatorname{GF}(2^8)</math>. This process is described further in the article [[Rijndael MixColumns]].
=== The {{mono | AddRoundKey}} step ===
[[Image:AES-AddRoundKey.svg|right|320px|thumbnail|In the {{mono | AddRoundKey}} step, each byte of the state is combined with a byte of the round subkey using the [[Exclusive or|XOR]] operation (⊕).]]
In the {{mono | AddRoundKey}} step, the subkey is combined with the state. For each round, a subkey is derived from the main [[key (cryptography)|key]] using [[Rijndael key schedule|Rijndael's key schedule]]; each subkey is the same size as the state. The subkey is added by combining each byte of the state with the corresponding byte of the subkey using bitwise [[Exclusive or|XOR]].
=== Optimization of the cipher ===
On systems with 32-bit or larger words, it is possible to speed up execution of this cipher by combining the {{mono | SubBytes}} and {{mono | ShiftRows}} steps with the {{mono | MixColumns}} step by transforming them into a sequence of table lookups. This requires four 256-entry 32-bit tables (together occupying 4096 bytes). A round can then be performed with 16 table lookup operations and 12 32-bit exclusive-or operations, followed by four 32-bit exclusive-or operations in the {{mono | AddRoundKey}} step.<ref>[http://www.springerlink.com/index/UVX5NQGNN55VK199.pdf "Efficient software implementation of AES on 32-bit platforms".] Lecture Notes in Computer Science: 2523. 2003</ref> Alternatively, the table lookup operation can be performed with a single 256-entry 32-bit table (occupying 1024 bytes) followed by circular rotation operations.
Using a byte-oriented approach, it is possible to combine the {{mono | SubBytes}}, {{mono | ShiftRows}}, and {{mono | MixColumns}} steps into a single round operation.<ref>{{cite web |url=https://code.google.com/p/byte-oriented-aes |title=byte-oriented-aes A public domain byte-oriented implementation of AES in C Google Project Hosting |accessdate=2012-12-23 |url-status=live |archiveurl=https://web.archive.org/web/20130720155538/http://code.google.com/p/byte-oriented-aes/ |archivedate=2013-07-20 }}</ref>
== Security ==
The [[National Security Agency]] (NSA) reviewed all the AES finalists, including Rijndael, and stated that all of them were secure enough for U.S. Government non-classified data. In June 2003, the U.S. Government announced that AES could be used to protect [[classified information]]:
<blockquote>The design and strength of all key lengths of the AES algorithm (i.e., 128, 192 and 256) are sufficient to protect classified information up to the SECRET level. TOP SECRET information will require use of either the 192 or 256 key lengths. The implementation of AES in products intended to protect national security systems and/or information must be reviewed and certified by NSA prior to their acquisition and use.<ref>{{cite web |url=http://csrc.nist.gov/groups/ST/toolkit/documents/aes/CNSS15FS.pdf |title=National Policy on the Use of the Advanced Encryption Standard (AES) to Protect National Security Systems and National Security Information |author=Lynn Hathaway |date=June 2003 |accessdate=2011-02-15 |url-status=live |archiveurl=https://web.archive.org/web/20101106122007/http://csrc.nist.gov/groups/ST/toolkit/documents/aes/CNSS15FS.pdf |archivedate=2010-11-06 }}</ref></blockquote>
AES has 10 rounds for 128-bit keys, 12 rounds for 192-bit keys, and 14 rounds for 256-bit keys.
By 2006, the best known attacks were on 7 rounds for 128-bit keys, 8 rounds for 192-bit keys, and 9 rounds for 256-bit keys.<ref name="improved">[[John Kelsey (cryptanalyst)|John Kelsey]], [[Stefan Lucks]], [[Bruce Schneier]], [[Mike Stay]], [[David A. Wagner|David Wagner]], and [[Doug Whiting]], ''Improved Cryptanalysis of Rijndael'', [[Fast Software Encryption]], 2000 pp213230 {{cite web |url=http://www.schneier.com/paper-rijndael.html |title=Academic: Improved Cryptanalysis of Rijndael - Schneier on Security |accessdate=2007-03-06 |url-status=live |archiveurl=https://web.archive.org/web/20070223215007/http://www.schneier.com/paper-rijndael.html |archivedate=2007-02-23 }}</ref>
=== Known attacks ===
For cryptographers, a [[cryptanalysis|cryptographic]] "break" is anything faster than a [[brute-force attack]] i.e., performing one trial decryption for each possible key in sequence (see [[Cryptanalysis#Computational resources required|Cryptanalysis]]). A break can thus include results that are infeasible with current technology. Despite being impractical, theoretical breaks can sometimes provide insight into vulnerability patterns. The largest successful publicly known brute-force attack against a widely implemented block-cipher encryption algorithm was against a 64-bit [[RC5]] key by [[distributed.net]] in 2006.<ref name=ZD20060430>{{cite web
|url=http://www.zdnet.com/blog/ou/is-encryption-really-crackable/204
|title=Is encryption really crackable?
|first1=George
|last1=Ou
|publisher=Ziff-Davis
|date=April 30, 2006
|archiveurl=https://web.archive.org/web/20100808173034/http://www.zdnet.com/blog/ou/is-encryption-really-crackable/204
|archivedate=August 8, 2010
|accessdate=August 7, 2010
|url-status=live
}}</ref>
The key space increases by a factor of 2 for each additional bit of key length, and if every possible value of the key is equiprobable, this translates into a doubling of the average brute-force key search time. This implies that the effort of a brute-force search increases exponentially with key length. Key length in itself does not imply security against attacks, since there are ciphers with very long keys that have been found to be vulnerable.
AES has a fairly simple algebraic framework.<ref>{{cite web |url=http://www.isg.rhul.ac.uk/~sean/ |title=Sean Murphy |publisher=University of London |accessdate=2008-11-02 |url-status=live |archiveurl=https://web.archive.org/web/20090131145521/http://www.isg.rhul.ac.uk/~sean/ |archivedate=2009-01-31 }}</ref> In 2002, a theoretical attack, named the “[[XSL attack]]”, was announced by [[Nicolas Courtois]] and [[Josef Pieprzyk]], purporting to show a weakness in the AES algorithm, partially due to the low complexity of its nonlinear components.<ref>{{cite web | url = http://www.schneier.com/crypto-gram-0209.html | title = AES News, Crypto-Gram Newsletter, September 15, 2002 | author = Bruce Schneier | accessdate = 2007-07-27| archiveurl= https://web.archive.org/web/20070707105715/http://www.schneier.com/crypto-gram-0209.html| archivedate= 7 July 2007 | url-status= live}}</ref> Since then, other papers have shown that the attack, as originally presented, is unworkable; see [[XSL attack#Application to block ciphers|XSL attack on block ciphers]].
During the AES selection process, developers of competing algorithms wrote of Rijndael's algorithm “...we are concerned about [its] use ... in security-critical applications.”<ref name="rijndael-algebraic">
{{cite conference
| author = Niels Ferguson
| author-link = Niels Ferguson
| author2 = Richard Schroeppel
| author2-link = Richard Schroeppel
| author3 = Doug Whiting
| title = A simple algebraic representation of Rijndael
| booktitle = Proceedings of Selected Areas in Cryptography, 2001, Lecture Notes in Computer Science
| pages = 103111
| publisher = [[Springer-Verlag]]
| date = 2001
| url = http://www.macfergus.com/pub/rdalgeq.html
| format = PDF/[[PostScript]]
| accessdate = 2006-10-06
| archiveurl= https://web.archive.org/web/20061104080748/http://www.macfergus.com/pub/rdalgeq.html
| archivedate= 4 November 2006| citeseerx = 10.1.1.28.4921
}}</ref> In October 2000, however, at the end of the AES selection process, [[Bruce Schneier]], a developer of the competing algorithm [[Twofish]], wrote that while he thought successful academic attacks on Rijndael would be developed someday, he did not “believe that anyone will ever discover an attack that will allow someone to read Rijndael traffic.”<ref>Bruce Schneier, [http://www.schneier.com/crypto-gram-0010.html AES Announced] {{webarchive|url=https://web.archive.org/web/20090201005720/http://www.schneier.com/crypto-gram-0010.html |date=2009-02-01 }}, October 15, 2000</ref>
Until May 2009, the only successful published attacks against the full AES were [[side-channel attack]]s on some specific implementations. In 2009, a new [[related-key attack]] was discovered that exploits the simplicity of AES's key schedule and has a complexity of 2<sup>119</sup>. In December 2009 it was improved to 2<sup>99.5</sup>.<ref name=relkey /> This is a follow-up to an attack discovered earlier in 2009 by [[Alex Biryukov]], [[Dmitry Khovratovich]], and Ivica Nikolić, with a complexity of 2<sup>96</sup> for one out of every 2<sup>35</sup> keys.<ref>{{cite book
|title=Advances in Cryptology CRYPTO 2009
|volume=5677
|chapter=Distinguisher and Related-Key Attack on the Full AES-256
|last1=Nikolić
|first1=Ivica
|date=2009
|publisher=Springer Berlin / Heidelberg
|isbn=978-3-642-03355-1
|pages=231249
|doi=10.1007/978-3-642-03356-8_14|series=Lecture Notes in Computer Science
}}</ref> However, related-key attacks are not of concern in any properly designed cryptographic protocol, as a properly designed protocol (i.e., implementational software) will take care not to allow related keys, essentially by [[Related-key attack#Preventing related-key attacks|constraining]] an attacker's means of selecting keys for relatedness.
Another attack was blogged by Bruce Schneier<ref>{{cite web
|url = http://www.schneier.com/blog/archives/2009/07/another_new_aes.html
|title = Another New AES Attack
|author = Bruce Schneier
|date = 2009-07-30
|work = Schneier on Security, A blog covering security and security technology
|accessdate = 2010-03-11
|url-status = live
|archiveurl = https://web.archive.org/web/20091005183132/http://www.schneier.com/blog/archives/2009/07/another_new_aes.html
|archivedate = 2009-10-05
}}</ref>
on July 30, 2009, and released as a preprint<ref>{{cite web
|url=http://eprint.iacr.org/2009/374
|title=Key Recovery Attacks of Practical Complexity on AES Variants With Up To 10 Rounds
|author=Alex Biryukov
|author2=Orr Dunkelman|author3= Nathan Keller|author4= Dmitry Khovratovich|author5= Adi Shamir
|date=2009-08-19
|accessdate=2010-03-11| archiveurl= https://web.archive.org/web/20100128050656/http://eprint.iacr.org/2009/374| archivedate= 28 January 2010 | url-status= live}}</ref>
on August 3, 2009. This new attack, by Alex Biryukov, Orr Dunkelman, Nathan Keller, Dmitry Khovratovich, and [[Adi Shamir]], is against AES-256 that uses only two related keys and 2<sup>39</sup> time to recover the complete 256-bit key of a 9-round version, or 2<sup>45</sup> time for a 10-round version with a stronger type of related subkey attack, or 2<sup>70</sup> time for an 11-round version. 256-bit AES uses 14 rounds, so these attacks aren't effective against full AES.
The practicality of these attacks with stronger related keys has been criticized,<ref>{{Cite book|title=On Some Symmetric Lightweight Cryptographic Designs|last=Agren|first=Martin|publisher=Dissertation, Lund University|year=2012|isbn=|location=|pages=3839}}</ref> for instance, by the paper on “chosen-key-relations-in-the-middle” attacks on AES-128 authored by Vincent Rijmen in 2010.<ref>{{cite journal |url=http://eprint.iacr.org/2010/337.pdf |title=Practical-Titled Attack on AES-128 Using Chosen-Text Relations |author=Vincent Rijmen |date=2010 |url-status=live |archiveurl=https://web.archive.org/web/20100702184311/http://eprint.iacr.org/2010/337.pdf |archivedate=2010-07-02 }}</ref>
In November 2009, the first [[known-key distinguishing attack]] against a reduced 8-round version of AES-128 was released as a preprint.<ref>{{cite web
|url = http://eprint.iacr.org/2009/531
|title = Super-Sbox Cryptanalysis: Improved Attacks for AES-like permutations
|author = Henri Gilbert
|author2 = Thomas Peyrin
|date = 2009-11-09
|accessdate = 2010-03-11
|url-status = live
|archiveurl = https://web.archive.org/web/20100604095754/http://eprint.iacr.org/2009/531
|archivedate = 2010-06-04
}}</ref>
This known-key distinguishing attack is an improvement of the rebound, or the start-from-the-middle attack, against AES-like permutations, which view two consecutive rounds of permutation as the application of a so-called Super-Sbox. It works on the 8-round version of AES-128, with a time complexity of 2<sup>48</sup>, and a memory complexity of 2<sup>32</sup>. 128-bit AES uses 10 rounds, so this attack isn't effective against full AES-128.
The first [[key-recovery attack]]s on full AES were due to Andrey Bogdanov, Dmitry Khovratovich, and Christian Rechberger, and were published in 2011.<ref>{{cite web|url=http://research.microsoft.com/en-us/projects/cryptanalysis/aesbc.pdf |title=Biclique Cryptanalysis of the Full AES |author=Andrey Bogdanov |author2=Dmitry Khovratovich |author3=Christian Rechberger |last-author-amp=yes |date=2011 |url-status=dead |archiveurl=https://web.archive.org/web/20120905154705/http://research.microsoft.com/en-us/projects/cryptanalysis/aesbc.pdf |archivedate=2012-09-05 }}</ref> The attack is a [[biclique attack]] and is faster than brute force by a factor of about four. It requires 2<sup>126.2</sup> operations to recover an AES-128 key. For AES-192 and AES-256, 2<sup>190.2</sup> and 2<sup>254.6</sup> operations are needed, respectively. This result has been further improved to 2<sup>126.0</sup> for AES-128, 2<sup>189.9</sup> for AES-192 and 2<sup>254.3</sup> for AES-256,<ref name=":0">{{cite book |author=Biaoshuai Tao |title = Information Security and Privacy|volume = 9144|pages = 3956|author2=Hongjun Wu |last-author-amp=yes |date=2015|doi=10.1007/978-3-319-19962-7_3 |series = Lecture Notes in Computer Science|isbn = 978-3-319-19961-0}}</ref> which are the current best results in key recovery attack against AES.
This is a very small gain, as a 126-bit key (instead of 128-bits) would still take billions of years to brute force on current and foreseeable hardware. Also, the authors calculate the best attack using their technique on AES with a 128 bit key requires storing 2<sup>88</sup> bits of data. That works out to about 38 trillion terabytes of data, which is more than all the data stored on all the computers on the planet in 2016. As such, there are no practical implications on AES security.<ref>{{cite web|author=Jeffrey Goldberg|title=AES Encryption isn't Cracked|url=https://blog.agilebits.com/2011/08/18/aes-encryption-isnt-cracked/|accessdate=30 December 2014|url-status=dead|archiveurl=https://web.archive.org/web/20150108165723/https://blog.agilebits.com/2011/08/18/aes-encryption-isnt-cracked/|archivedate=8 January 2015|date=2011-08-18}}</ref> The space complexity has later been improved to 2<sup>56</sup> bits,<ref name=":0"/> which is 9007 terabytes.
According to the [[Edward Snowden#Global surveillance disclosures|Snowden documents]], the NSA is doing research on whether a cryptographic attack based on [[Kendall tau rank correlation coefficient|tau statistic]] may help to break AES.<ref>{{cite news|url=http://www.spiegel.de/international/germany/inside-the-nsa-s-war-on-internet-security-a-1010361.html|title=Inside the NSA's War on Internet Security|author=((SPIEGEL ONLINE, Hamburg, Germany))|date=28 December 2014|newspaper=SPIEGEL ONLINE|accessdate=4 September 2015|url-status=live|archiveurl=https://web.archive.org/web/20150124202809/http://www.spiegel.de/international/germany/inside-the-nsa-s-war-on-internet-security-a-1010361.html|archivedate=24 January 2015}}</ref>
At present, there is no known practical attack that would allow someone without knowledge of the key to read data encrypted by AES when correctly implemented.
=== Side-channel attacks ===
<!-- possibly out of date? -->
[[Side-channel attacks]] do not attack the cipher as a [[black box]], and thus are not related to cipher security as defined in the classical context, but are important in practice. They attack implementations of the cipher on hardware or software systems that inadvertently leak data. There are several such known attacks on various implementations of AES.
In April 2005, [[Daniel J. Bernstein|D.J. Bernstein]] announced a cache-timing attack that he used to break a custom server that used [[OpenSSL]]s AES encryption.<ref name="bernstein_timing">{{cite web |url=http://cr.yp.to/papers.html#cachetiming |title=Index of formal scientific papers |publisher=Cr.yp.to |accessdate=2008-11-02 |url-status=live |archiveurl=https://web.archive.org/web/20080917042758/http://cr.yp.to/papers.html#cachetiming |archivedate=2008-09-17 }}</ref> The attack required over 200 million chosen plaintexts.<ref>{{cite web | url = http://www.schneier.com/blog/archives/2005/05/aes_timing_atta_1.html | title = AES Timing Attack | author = Bruce Schneier | accessdate = 2007-03-17| archiveurl= https://web.archive.org/web/20070212015727/http://www.schneier.com/blog/archives/2005/05/aes_timing_atta_1.html| archivedate= 12 February 2007 | url-status= live}}</ref> The custom server was designed to give out as much timing information as possible (the server reports back the number of machine cycles taken by the encryption operation). However, as Bernstein pointed out, “reducing the precision of the servers timestamps, or eliminating them from the servers responses, does not stop the attack: the client simply uses round-trip timings based on its local clock, and compensates for the increased noise by averaging over a larger number of samples.”<ref name="bernstein_timing" />
In October 2005, Dag Arne Osvik, [[Adi Shamir]] and Eran Tromer presented a paper demonstrating several cache-timing attacks against the implementations in AES found in OpenSSL and Linux's <code>dm-crypt</code> partition encryption function.<ref>{{cite journal |url=http://www.wisdom.weizmann.ac.il/~tromer/papers/cache.pdf |title=Cache Attacks and Countermeasures: the Case of AES |date=2005-11-20 |author=Dag Arne Osvik |author2=Adi Shamir |author3=Eran Tromer |accessdate=2008-11-02 |url-status=live |archiveurl=https://web.archive.org/web/20060619221046/http://www.wisdom.weizmann.ac.il/%7Etromer/papers/cache.pdf |archivedate=2006-06-19 }}</ref> One attack was able to obtain an entire AES key after only 800 operations triggering encryptions, in a total of 65 milliseconds. This attack requires the attacker to be able to run programs on the same system or platform that is performing AES.
In December 2009 an attack on some hardware implementations was published that used [[differential fault analysis]] and allows recovery of a key with a complexity of 2<sup>32</sup>.<ref>{{cite journal|url=http://eprint.iacr.org/2009/581.pdf |title=A Diagonal Fault Attack on the Advanced Encryption Standard |author=Dhiman Saha |author2=Debdeep Mukhopadhyay |author3=Dipanwita RoyChowdhury |accessdate=2009-12-08| archiveurl= https://web.archive.org/web/20091222070135/http://eprint.iacr.org/2009/581.pdf| archivedate= 22 December 2009 | url-status= live}}</ref>
In November 2010 Endre Bangerter, David Gullasch and Stephan Krenn published a paper which described a practical approach to a “near real time” recovery of secret keys from AES-128 without the need for either cipher text or plaintext. The approach also works on AES-128 implementations that use compression tables, such as OpenSSL.<ref>{{cite journal |url=http://eprint.iacr.org/2010/594.pdf |title=Cache Games Bringing Access-Based Cache Attacks on AES to Practice |author=Endre Bangerter |author2=David Gullasch |author3=Stephan Krenn |last-author-amp=yes |date=2010 |url-status=live |archiveurl=https://web.archive.org/web/20101214092512/http://eprint.iacr.org/2010/594.pdf |archivedate=2010-12-14 }}</ref> Like some earlier attacks this one requires the ability to run unprivileged code on the system performing the AES encryption, which may be achieved by malware infection far more easily than commandeering the root account.<ref>{{cite web |url=http://news.ycombinator.com/item?id=1937902 |title=Breaking AES-128 in realtime, no ciphertext required {{!}} Hacker News |publisher=News.ycombinator.com |accessdate=2012-12-23 |url-status=live |archiveurl=https://web.archive.org/web/20111003193004/http://news.ycombinator.com/item?id=1937902 |archivedate=2011-10-03 }}</ref>
In March 2016, Ashokkumar C., Ravi Prakash Giri and Bernard Menezes presented a very efficient side-channel attack on AES implementations that can recover the complete 128-bit AES key in just 67 blocks of plaintext/ciphertext which is a substantial improvement over previous works that require between 100 and a million encryptions.<ref>{{cite book | year=2016 | author1=Ashokkumar C. |title = 2016 IEEE European Symposium on Security and Privacy (EuroS&P)| pages=261275 | author2=Ravi Prakash Giri | author3=Bernard Menezes | df= | doi=10.1109/EuroSP.2016.29 | isbn=978-1-5090-1751-5 }}</ref> The proposed attack requires standard user privilege as previous attacks and key-retrieval algorithms run under a minute.
Many modern CPUs have built-in [[AES instruction set|hardware instructions for AES]], which would protect against timing-related side-channel attacks.<ref>{{cite web |url=https://cseweb.ucsd.edu/~kmowery/papers/aes-cache-timing.pdf |title=Are AES x86 Cache Timing Attacks Still Feasible? |website=cseweb.ucsd.edu |url-status=live |archiveurl=https://web.archive.org/web/20170809152309/http://cseweb.ucsd.edu/~kmowery/papers/aes-cache-timing.pdf |archivedate=2017-08-09 }}</ref><ref>{{cite web |url=https://www.intel.in/content/dam/doc/white-paper/enterprise-security-aes-ni-white-paper.pdf |title=Archived copy |accessdate=2017-07-26 |url-status=live |archiveurl=https://web.archive.org/web/20130331041411/http://www.intel.in/content/dam/doc/white-paper/enterprise-security-aes-ni-white-paper.pdf |archivedate=2013-03-31 }} Securing the Enterprise with Intel AES-NI</ref>
== NIST/CSEC validation ==
The [[CMVP|Cryptographic Module Validation Program]] (CMVP) is operated jointly by the United States Government's [[National Institute of Standards and Technology]] (NIST) Computer Security Division and the [[Communications Security Establishment]] (CSE) of the Government of Canada. The use of cryptographic modules validated to NIST [[FIPS 140-2]] is required by the United States Government for encryption of all data that has a classification of Sensitive but Unclassified (SBU) or above. From NSTISSP #11, National Policy Governing the Acquisition of Information Assurance: “Encryption products for protecting classified information will be certified by NSA, and encryption products intended for protecting sensitive information will be certified in accordance with NIST FIPS 140-2.”<ref name="cnss.gov">{{cite web |url=http://www.cnss.gov/Assets/pdf/nstissp_11_fs.pdf |title=Archived copy |accessdate=2012-05-29 |url-status=dead |archiveurl=https://web.archive.org/web/20120421103818/http://www.cnss.gov/Assets/pdf/nstissp_11_fs.pdf |archivedate=2012-04-21 }}</ref>
The Government of Canada also recommends the use of [[FIPS 140]] validated cryptographic modules in unclassified applications of its departments.
Although NIST publication 197 (“FIPS 197”) is the unique document that covers the AES algorithm, vendors typically approach the CMVP under FIPS 140 and ask to have several algorithms (such as [[Triple DES|Triple&nbsp;DES]] or [[SHA1]]) validated at the same time. Therefore, it is rare to find cryptographic modules that are uniquely FIPS 197 validated and NIST itself does not generally take the time to list FIPS 197 validated modules separately on its public web site. Instead, FIPS 197 validation is typically just listed as an "FIPS approved: AES" notation (with a specific FIPS 197 certificate number) in the current list of FIPS 140 validated cryptographic modules.
The Cryptographic Algorithm Validation Program (CAVP)<ref>{{cite web |url=http://csrc.nist.gov/groups/STM/cavp/index.html |title=NIST.gov Computer Security Division Computer Security Resource Center |publisher=Csrc.nist.gov |accessdate=2012-12-23 |url-status=live |archiveurl=https://web.archive.org/web/20130102044410/http://csrc.nist.gov/groups/STM/cavp/index.html |archivedate=2013-01-02 }}</ref> allows for independent validation of the correct implementation of the AES algorithm at a reasonable cost{{Citation needed|date=December 2010}}. Successful validation results in being listed on the NIST validations page.<ref>{{cite web|url=http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/140val-all.htm|title=Validated FIPS 140-1 and FIPS 140-2 Cryptographic Modules|url-status=dead|archiveurl=https://web.archive.org/web/20141226152243/http://csrc.nist.gov/groups/STM/cmvp/documents/140-1/140val-all.htm|archivedate=2014-12-26|access-date=2014-06-26}}</ref> This testing is a pre-requisite for the FIPS 140-2 module validation described below. However, successful CAVP validation in no way implies that the cryptographic module implementing the algorithm is secure. A cryptographic module lacking FIPS 140-2 validation or specific approval by the NSA is not deemed secure by the US Government and cannot be used to protect government data.<ref name="cnss.gov"/>
FIPS 140-2 validation is challenging to achieve both technically and fiscally.<ref name="openssl">{{cite web |author=OpenSSL, openssl@openssl.org |url=http://openssl.org/docs/fips/fipsnotes.html |title=OpenSSL's Notes about FIPS certification |publisher=Openssl.org |accessdate=2012-12-23 |url-status=dead |archiveurl=https://web.archive.org/web/20130102203126/http://www.openssl.org/docs/fips/fipsnotes.html |archivedate=2013-01-02 }}</ref> There is a standardized battery of tests as well as an element of source code review that must be passed over a period of a few weeks. The cost to perform these tests through an approved laboratory can be significant (e.g., well over $30,000 US)<ref name="openssl" /> and does not include the time it takes to write, test, document and prepare a module for validation. After validation, modules must be re-submitted and re-evaluated if they are changed in any way. This can vary from simple paperwork updates if the security functionality did not change to a more substantial set of re-testing if the security functionality was impacted by the change.
== Test vectors ==
Test vectors are a set of known ciphers for a given input and key. NIST distributes the reference of AES test vectors as AES Known Answer Test (KAT) Vectors.<ref group="note">The AES Known Answer Test (KAT) Vectors are available in Zip format within the NIST site [http://csrc.nist.gov/groups/STM/cavp/documents/aes/KAT_AES.zip here] {{webarchive|url=https://web.archive.org/web/20091023001419/http://csrc.nist.gov/groups/STM/cavp/documents/aes/KAT_AES.zip |date=2009-10-23 }}</ref>
== Performance ==
High speed and low RAM requirements were criteria of the AES selection process. As the chosen algorithm, AES performed well on a wide variety of hardware, from 8-bit [[smart card]]s to high-performance computers.
On a [[Pentium Pro]], AES encryption requires 18 clock cycles per byte,<ref>{{cite web |url=http://www.schneier.com/paper-aes-performance.pdf |title=Performance Comparisons of the AES submissions |last1=Schneier |first1=Bruce |last2=Kelsey |first2=John |last3=Whiting |first3=Doug |last4=Wagner |first4=David |last5=Hall |first5=Chris |last6=Ferguson |first6=Niels |date=1999-02-01 |accessdate=2010-12-28 |url-status=live |archiveurl=https://web.archive.org/web/20110622084238/http://www.schneier.com/paper-aes-performance.pdf |archivedate=2011-06-22 }}</ref> equivalent to a throughput of about 11&nbsp;Mbit/s for a 200&nbsp;MHz processor. On a 1.7&nbsp;GHz [[Pentium M]] throughput is about 60&nbsp;Mbit/s.
On Intel [[Core i3]]/[[Core i5|i5]]/[[Core i7|i7]] and [[AMD Ryzen]] CPUs supporting [[AES instruction set|AES-NI instruction set]] extensions, throughput can be multiple GB/s (even over 10&nbsp;GB/s).<ref>{{cite web |url=https://www.vortez.net/articles_pages/amd_ryzen_7_1700x_review,7.html |title=AMD Ryzen 7 1700X Review}}</ref>
== Implementations ==
{{Main|AES implementations}}
== See also ==
*[[Disk encryption]]
*[[Network encryption]]
*[[Whirlpool (cryptography)|Whirlpool]] hash function created by Vincent Rijmen and Paulo S. L. M. Barreto
== Notes ==
<references group="note"
/>
== References ==
{{Reflist}}
{{refbegin}}
*{{cite book |first=Nicolas |last=Courtois |first2=Josef |last2=Pieprzyk |chapter=Cryptanalysis of Block Ciphers with Overdefined Systems of Equations |editor-first=Yuliang |editor-last=Zheng |title=Advances in Cryptology — ASIACRYPT 2002: 8th International Conference on the Theory and Application of Cryptology and Information Security, Queenstown, New Zealand, December 15, 2002, Proceedings |chapterurl=https://books.google.com/books?id=OZ1qCQAAQBAJ&pg=PA268 |date=2003 |publisher=Springer |isbn=978-3-540-36178-7 |pages=268287|title-link=ASIACRYPT }}
*{{cite book |first=Joan |last=Daemen |first2=Vincent |last2=Rijmen |title=The Design of Rijndael: AES — The Advanced Encryption Standard |url=https://books.google.com/books?id=tfjd6icCUoYC&pg=PR4 |date=2002 |publisher=Springer |isbn=978-3-540-42580-9 }}
*{{cite book |first=Christof |last=Paar |first2=Jan |last2=Pelzl |title=Understanding Cryptography: A Textbook for Students and Practitioners |url=https://books.google.com/books?id=f24wFELSzkoC&pg=PA87 |date=2009 |publisher=Springer |isbn=978-3-642-04101-3 |pages=87122}} [https://archive.today/20130105232834/http://wiki.crypto.rub.de/Buch/sample_chapters.php alternate link] (companion web site contains online lectures on AES)
{{refend}}
== External links ==
*{{cite web |title=256bit key — 128bit block — AES |date= |work=Cryptography — 256 bit Ciphers: Reference source code and submissions to international cryptographic designs contests |publisher=EmbeddedSW |url=http://embeddedsw.net/Cipher_Reference_Home.html}}
*{{cite journal |title=Advanced Encryption Standard (AES) |date=26 November 2001 |journal=Federal Information Processing Standards |id=197 |url=http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197.pdf |doi=10.6028/NIST.FIPS.197}}
* [http://csrc.nist.gov/archive/aes/rijndael/wsdindex.html AES algorithm archive information (old, unmaintained)]
*{{cite web |title=Part 3: Block ciphers |date=2010-12-15 |work=Information technology — Security techniques — Encryption algorithms |publisher=ISO |edition=2nd |id=ISO/IEC 18033-3:2010(E) |url=https://webstore.iec.ch/preview/info_isoiec18033-3%7Bed2.0%7Den.pdf }}
* [http://www.formaestudio.com/rijndaelinspector/archivos/Rijndael_Animation_v4_eng.swf Animation of Rijndael] AES deeply explained and animated using Flash (by Enrique Zabala / University ORT / Montevideo / Uruguay). This animation (in English, Spanish, and German) is also part of [[CrypTool|CrypTool 1]] (menu Indiv. Procedures -> Visualization of Algorithms -> AES).
{{Cryptography navbox | block}}
* [https://formaestudio.com/rijndaelinspector/archivos/Rijndael_Animation_v4_eng-html5.html HTML5 Animation of Rijndael ] Same Animation as above made in HTML5.
[[Category:Advanced Encryption Standard| ]]

View file

@ -42,6 +42,18 @@ A GIF animation of Gandalf from The Lord of the Rings.
SHA-256 hash: `8f701aeb296882d5a244d71287e12bd05353dacdf15b1f83f767749f628cd1c2`
## `CryptTextExample.txt`
### Parameters
- **Encrypt** (Password: `HelloWorld`)
### Can be stitched into
The wikitext for the [AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) Wikipedia article.
SHA-256 hash: `42505823d00e2661e0b271e03f440ed4ad5b54e546874de96a6633352eebfb93`
## `ForkExample.txt`
### Parameters

View file

@ -7,6 +7,7 @@ import javax.crypto.spec.*;
import java.io.*;
import java.security.*;
import java.security.spec.*;
import java.util.Objects;
/**
* A {@link ICleaverInputStream} that decrypts incoming data using a {@link Cipher} object.
@ -136,4 +137,51 @@ public class CleaverCryptInputStream extends FilterInputStream implements ICleav
byte[] decryptedByte = cipher.update(encryptedByte);
return decryptedByte[0];
}
/**
* Force reads of 1 byte at a time by overriding {@link FilterInputStream#read(byte[])} with the code from {@link InputStream#read(byte[])}.
* @param b The buffer to read the data into.
* @return The number of read bytes, or -1 if the end of the {@link #in} stream has been reached.
* @throws IOException If an error occours during the read.
*/
@Override
public int read(byte[] b) throws IOException {
return this.read(b, 0, b.length);
}
/**
* Force reads of 1 byte at a time by overriding {@link FilterInputStream#read(byte[], int, int)} with the code from
* {@link InputStream#read(byte[], int, int)}.
* @param b The buffer to read the data into.
* @param off The first position of the <code>b</code> buffer where the data should be read into.
* @param len The maximum number of bytes to read.
* @return The number of read bytes, or -1 if the end of the {@link #in} stream has been reached.
* @throws IOException If an error occours during the read.
*/
@Override
public int read(byte[] b, int off, int len) throws IOException {
Objects.checkFromIndexSize(off, len, b.length);
if (len == 0) {
return 0;
}
int c = read();
if (c == -1) {
return -1;
}
b[off] = (byte)c;
int i = 1;
try {
for (; i < len ; i++) {
c = read();
if (c == -1) {
break;
}
b[off + i] = (byte)c;
}
} catch (IOException ee) {
}
return i;
}
}

View file

@ -8,6 +8,8 @@ import javax.crypto.spec.*;
import java.io.*;
import java.security.*;
import java.security.spec.*;
import java.util.Objects;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -167,6 +169,33 @@ public class CleaverCryptOutputStream extends FilterOutputStream implements ICle
super.write(encryptedInt);
}
/**
* Force writes of 1 byte at a time by overriding {@link FilterOutputStream#write(byte[])} with the code from
* {@link OutputStream#write(byte[])}.
* @param b The buffer from where the data should be written.
* @throws IOException If an error occours during the write.
*/
public void write(byte[] b) throws IOException {
write(b, 0, b.length);
}
/**
* Force writes of 1 byte at a time by overriding {@link FilterOutputStream#write(byte[], int, int)} with the code from
* {@link OutputStream#write(byte[], int, int)}.
* @param b The buffer from where the data should be written.
* @param off The first position of the {@literal b} buffer from where the data should be written.
* @param len The maximum number of bytes to write.
* @throws IOException If an error occours during the write.
*/
@Override
public void write(byte[] b, int off, int len) throws IOException {
Objects.checkFromIndexSize(off, len, b.length);
for (int i = 0 ; i < len ; i++) {
write(b[off + i]);
}
}
@Override
public Element toElement(Document doc) {
Element element = doc.createElement("Crypt");