encryption_info.hpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (c) 2017-2021 Thomas Fussell
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE
  20. //
  21. // @license: http://www.opensource.org/licenses/mit-license.php
  22. // @author: see AUTHORS file
  23. #include <cstdint>
  24. #include <string>
  25. #include <vector>
  26. #include <detail/cryptography/cipher.hpp>
  27. #include <detail/cryptography/hash.hpp>
  28. namespace xlnt {
  29. namespace detail {
  30. struct encryption_info
  31. {
  32. bool is_agile = true;
  33. std::u16string password;
  34. struct standard_encryption_info
  35. {
  36. std::size_t spin_count = 50000;
  37. std::size_t block_size;
  38. std::size_t key_bits;
  39. std::size_t key_bytes;
  40. std::size_t hash_size;
  41. cipher_algorithm cipher;
  42. cipher_chaining chaining;
  43. hash_algorithm hash = hash_algorithm::sha1;
  44. std::vector<std::uint8_t> salt;
  45. std::vector<std::uint8_t> encrypted_verifier;
  46. std::vector<std::uint8_t> encrypted_verifier_hash;
  47. } standard;
  48. struct agile_encryption_info
  49. {
  50. // key data
  51. struct
  52. {
  53. std::size_t salt_size;
  54. std::size_t block_size;
  55. std::size_t key_bits;
  56. std::size_t hash_size;
  57. std::string cipher_algorithm;
  58. std::string cipher_chaining;
  59. std::string hash_algorithm;
  60. std::vector<std::uint8_t> salt_value;
  61. } key_data;
  62. struct
  63. {
  64. std::vector<std::uint8_t> hmac_key;
  65. std::vector<std::uint8_t> hmac_value;
  66. } data_integrity;
  67. struct
  68. {
  69. std::size_t spin_count;
  70. std::size_t salt_size;
  71. std::size_t block_size;
  72. std::size_t key_bits;
  73. std::size_t hash_size;
  74. std::string cipher_algorithm;
  75. std::string cipher_chaining;
  76. hash_algorithm hash;
  77. std::vector<std::uint8_t> salt_value;
  78. std::vector<std::uint8_t> verifier_hash_input;
  79. std::vector<std::uint8_t> verifier_hash_value;
  80. std::vector<std::uint8_t> encrypted_key_value;
  81. } key_encryptor;
  82. } agile;
  83. std::vector<std::uint8_t> calculate_key() const;
  84. };
  85. } // namespace detail
  86. } // namespace xlnt