pbkdf_pkcs12_test.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # test data from test.c
  2. import wolfssl
  3. KEY_LENGTH = 24
  4. SHA256 = 2 # Hashtype, stands for Sha256 in wolfssl.
  5. def to_c_byte_array(content):
  6. output = wolfssl.byteArray(len(content))
  7. for i, ch in enumerate(content):
  8. output[i] = ord(ch)
  9. return output
  10. password = '\x00\x73\x00\x6d\x00\x65\x00\x67\x00\x00'
  11. salt = '\x0a\x58\xCF\x64\x53\x0d\x82\x3f'
  12. key = wolfssl.byteArray(KEY_LENGTH)
  13. verify = '\x27\xE9\x0D\x7E\xD5\xA1\xC4\x11\xBA\x87\x8B\xC0\x90\xF5\xCE\xBE\x5E\x9D\x5F\xE3\xD6\x2B\x73\xAA'
  14. wolfssl.wc_PKCS12_PBKDF(key, to_c_byte_array(password), len(password),
  15. to_c_byte_array(salt), len(salt), 1, KEY_LENGTH,
  16. SHA256, 1)
  17. key = wolfssl.cdata(key, KEY_LENGTH)
  18. assert key == verify
  19. password = '\x00\x71\x00\x75\x00\x65\x00\x65\x00\x67\x00\x00'
  20. salt = '\x16\x82\xC0\xfC\x5b\x3f\x7e\xc5'
  21. key = wolfssl.byteArray(KEY_LENGTH)
  22. verify = '\x90\x1B\x49\x70\xF0\x94\xF0\xF8\x45\xC0\xF3\xF3\x13\x59\x18\x6A\x35\xE3\x67\xFE\xD3\x21\xFD\x7C'
  23. wolfssl.wc_PKCS12_PBKDF(key, to_c_byte_array(password), len(password),
  24. to_c_byte_array(salt), len(salt), 1000, KEY_LENGTH,
  25. SHA256, 1)
  26. key = wolfssl.cdata(key, KEY_LENGTH)
  27. assert key == verify