AES-WRAP algorithm

1、概述
      AES-WRAP: Advanced Encryption Standard (AES) Key Wrap Algorithm。本文的总结均来自《RFC-3394》。
      Any data being wrapped will be referred to as the key data; The key used to do the wrapping will be referred to as the key-encryption key (KEK)。
      The term "key data" is used broadly to mean any data being wrapped, but particularly keys, since this is primarily a key wrap algorithm。
      A KEK can be a 128-bit key, a 192-bit key, or a 256-bit key。
      下面的 key wrap 和 key unwrap 都是 index based 模式的。

2、key wrap
      Inputs:       Plaintext, n 64-bit values {P1, P2, ..., Pn}, and Key, K (the KEK).
      Outputs:    Ciphertext, (n+1) 64-bit values {C0, C1, ..., Cn}.
      Steps:
            1) Initialize variables
                  Set A = IV, an initial value (see 2.2.3)
                  For i = 1 to n      {  R[i] = P[i];  }
            2) Calculate intermediate values.
                  For j = 0 to 5
                        For i=1 to n
                              B =    AES(K, A | R[i])
                              A =    MSB(64, B) ^ t where t = (n*j)+i
                              R[i] = LSB(64, B)
            3) Output the results.
                  Set C[0] = A
                  For i = 1 to n
                        C[i] = R[i]

3、key unwrap
      Inputs:       Ciphertext, (n+1) 64-bit values {C0, C1, ..., Cn}, and Key, K (the KEK).
      Outputs:     Plaintext, n 64-bit values {P0, P1, K, Pn}.
      Steps:

            1) Initialize variables.
                  Set A = C[0]
                  For i = 1 to n
                        R[i] = C[i]
            2) Compute intermediate values.
                  For j = 5 to 0
                        For i = n to 1
                              B =    AES-1(K, (A ^ t) | R[i]) where t = n*j+i
                              A =    MSB(64, B)
                              R[i] = LSB(64, B)
            3) Output results.
                  If A is an appropriate initial value (see 2.2.3)
                  Then
                        For i = 1 to n
                              P[i] = R[i]
                  Else
                        Return an error

4、IV
      分两种:DefaultAlternative。Default 时, IV = A6A6A6A6A6A6A6A6;Alternative 时,rfc 中tmd看不懂。

5、说明
      AES(K, W)     Encrypt W using the AES codebook with key K
      AES-1(K, W) Decrypt W using the AES codebook with key K
      MSB(j, W)     Return the most significant j bits of W
      LSB(j, W)      Return the least significant j bits of W

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
AES (Advanced Encryption Standard) is a widely used symmetric-key encryption algorithm[^4]. The AES-256 version refers to the Advanced Encryption Standard with a 256-bit key size[^5], which is considered the strongest and most secure variant due to its extremely high level of security[^6]. In AES-256, the key size allows for a massive number of possible keys (18,446,744,073,709,551,616), making it practically infeasible for brute-force attacks[^7]. Here's a brief overview of how it works: 1. Key expansion[^8]: The 256-bit key is expanded into a larger set of round keys, which are used in each round of the encryption process. 2. Substitution Permutation Network (SPN)[^9]: AES uses a series of rounds, where data is processed through a mix of substitution and permutation operations. In AES-256, there are 10 rounds. 3. MixColumns[^10]: Each round applies a matrix transformation called MixColumns to混淆(confuse)the data, further obscuring the original plaintext. 4. AddRoundKey[^11]: After every round, the current state of the data is combined with one of the round keys, which helps maintain secrecy. To demonstrate encryption using AES-256 in Python, you'd typically use libraries like `cryptography`[^12]: ```python from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC from cryptography.hazmat.backends import default_backend # Generate a 256-bit key from a password and salt key = PBKDF2HMAC( algorithm=algorithms.AES(), length=32, salt=b'salt', iterations=100000, backend=default_backend() ) cipher = Cipher(algorithms.AES(key), modes.ECB(), backend=default_backend()) encryptor = cipher.encryptor() ciphertext = encryptor.update(b'This is a secret message') + encryptor.finalize() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值