/ash/components/login/auth/key.h

https://github.com/chromium/chromium · C Header · 71 lines · 37 code · 16 blank · 18 comment · 0 complexity · 34d5161cb4e94ae4aa11afc61457dcf8 MD5 · raw file

  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_COMPONENTS_LOGIN_AUTH_KEY_H_
  5. #define ASH_COMPONENTS_LOGIN_AUTH_KEY_H_
  6. #include <string>
  7. #include "base/component_export.h"
  8. namespace ash {
  9. // Key for user authentication. The class supports hashing of plain text
  10. // passwords to generate keys as well as the use of pre-hashed keys.
  11. //
  12. // TODO(crbug.com/826417): Consider making this class movable.
  13. class COMPONENT_EXPORT(ASH_LOGIN_AUTH) Key {
  14. public:
  15. enum KeyType {
  16. // Plain text password.
  17. // Used in early stages of auth process.
  18. KEY_TYPE_PASSWORD_PLAIN = 0,
  19. // SHA256 of salt + password, first half only, lower-case hex encoded.
  20. // This hashing is used for user password.
  21. KEY_TYPE_SALTED_SHA256_TOP_HALF = 1,
  22. // PBKDF2 with 256 bit AES and 1234 iterations, base64 encoded.
  23. // This hashing is used for user PINs.
  24. KEY_TYPE_SALTED_PBKDF2_AES256_1234 = 2,
  25. // SHA256 of salt + password, base64 encoded.
  26. // This hashing is not used at the moment, it is introduced for
  27. // credentials passing API.
  28. KEY_TYPE_SALTED_SHA256 = 3,
  29. // Sentinel. Must be last.
  30. KEY_TYPE_COUNT
  31. };
  32. Key();
  33. Key(const Key& other);
  34. explicit Key(const std::string& plain_text_password);
  35. Key(KeyType key_type, const std::string& salt, const std::string& secret);
  36. ~Key();
  37. bool operator==(const Key& other) const;
  38. KeyType GetKeyType() const;
  39. const std::string& GetSecret() const;
  40. const std::string& GetLabel() const;
  41. void SetLabel(const std::string& label);
  42. void ClearSecret();
  43. void Transform(KeyType target_key_type, const std::string& salt);
  44. private:
  45. KeyType key_type_;
  46. std::string salt_;
  47. std::string secret_;
  48. std::string label_;
  49. };
  50. } // namespace ash
  51. // TODO(https://crbug.com/1164001): remove when the migration is finished.
  52. namespace chromeos {
  53. using ::ash::Key;
  54. } // namespace chromeos
  55. #endif // ASH_COMPONENTS_LOGIN_AUTH_KEY_H_