fast_crypto_ops.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "crypto/common.h"
  15. #include "crypto/aes_wrap.h"
  16. #include "crypto/sha256.h"
  17. #include "crypto/crypto.h"
  18. #include "esp_wifi_crypto_types.h"
  19. /*
  20. * The parameters is used to set the cyrpto callback function for station connect when in security mode,
  21. * every callback function can register as fast_xxx or normal one, i.e, fast_aes_wrap or aes_wrap, the
  22. * difference between them is the normal API is calculate by software, the fast one use the hardware
  23. * crypto in it, can be faster than the normal one, so the callback function register in default is which
  24. * we recommend, so as the API in WPS default and WPA2 default.
  25. */
  26. const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = {
  27. .aes_wrap = (esp_aes_wrap_t)fast_aes_wrap,
  28. .aes_unwrap = (esp_aes_unwrap_t)fast_aes_unwrap,
  29. .hmac_sha256_vector = (esp_hmac_sha256_vector_t)fast_hmac_sha256_vector,
  30. .sha256_prf = (esp_sha256_prf_t)fast_sha256_prf
  31. };
  32. const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs = {
  33. .aes_128_encrypt = (esp_aes_128_encrypt_t)fast_aes_128_cbc_encrypt,
  34. .aes_128_decrypt = (esp_aes_128_decrypt_t)fast_aes_128_cbc_decrypt,
  35. .crypto_mod_exp = (esp_crypto_mod_exp_t)fast_crypto_mod_exp,
  36. .hmac_sha256 = (esp_hmac_sha256_t)fast_hmac_sha256,
  37. .hmac_sha256_vector = (esp_hmac_sha256_vector_t)fast_hmac_sha256_vector,
  38. .sha256_vector = (esp_sha256_vector_t)fast_sha256_vector
  39. };
  40. /*
  41. * What should notice is that the cyrpto hash type function and crypto cipher type function can not register
  42. * as different, i.e, if you use fast_crypto_hash_init, you should use fast_crypto_hash_update and
  43. * fast_crypto_hash_finish for finish hash calculate, rather than call crypto_hash_update and
  44. * crypto_hash_finish, so do crypto_cipher.
  45. */
  46. const wpa2_crypto_funcs_t g_wifi_default_wpa2_crypto_funcs = {
  47. .crypto_hash_init = (esp_crypto_hash_init_t)fast_crypto_hash_init,
  48. .crypto_hash_update = (esp_crypto_hash_update_t)fast_crypto_hash_update,
  49. .crypto_hash_finish = (esp_crypto_hash_finish_t)fast_crypto_hash_finish,
  50. .crypto_cipher_init = (esp_crypto_cipher_init_t)fast_crypto_cipher_init,
  51. .crypto_cipher_encrypt = (esp_crypto_cipher_encrypt_t)fast_crypto_cipher_encrypt,
  52. .crypto_cipher_decrypt = (esp_crypto_cipher_decrypt_t)fast_crypto_cipher_decrypt,
  53. .crypto_cipher_deinit = (esp_crypto_cipher_deinit_t)fast_crypto_cipher_deinit,
  54. .sha256_vector = (esp_sha256_vector_t)fast_sha256_vector,
  55. .crypto_mod_exp = (esp_crypto_mod_exp_t)crypto_mod_exp
  56. };