Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.9 KiB

  1. // MsRsaPubKB.cpp -- MicroSoft RSA Public Key Blob class implementation
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #include "NoWarning.h"
  8. #include "ForceLib.h"
  9. #include <limits>
  10. #include <windows.h>
  11. #include "MsRsaPubKB.h"
  12. using namespace std;
  13. using namespace scu;
  14. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  15. namespace
  16. {
  17. MsRsaPublicKeyBlob::StrengthType
  18. Strength(Blob::size_type st)
  19. {
  20. return st *
  21. numeric_limits<MsRsaPublicKeyBlob::ElementValueType>::digits;
  22. }
  23. MsRsaPublicKeyBlob::SizeType
  24. Reserve(Blob::size_type st)
  25. {
  26. return st * sizeof MsRsaPublicKeyBlob::HeaderElementType;
  27. }
  28. }
  29. /////////////////////////// PUBLIC /////////////////////////////////
  30. // Types
  31. // C'tors/D'tors
  32. MsRsaPublicKeyBlob::MsRsaPublicKeyBlob(ALG_ID algid,
  33. Blob const &rblbPublicExponent,
  34. Blob const &rblbRawModulus)
  35. : MsRsaKeyBlob(PUBLICKEYBLOB, algid,
  36. Strength(rblbRawModulus.length()),
  37. rblbPublicExponent,
  38. Reserve(rblbRawModulus.length()))
  39. {
  40. Init(rblbRawModulus);
  41. }
  42. MsRsaPublicKeyBlob::MsRsaPublicKeyBlob(BYTE const *pbData,
  43. DWORD dwDataLength)
  44. : MsRsaKeyBlob(pbData, dwDataLength)
  45. {}
  46. MsRsaPublicKeyBlob::~MsRsaPublicKeyBlob()
  47. {}
  48. // Operators
  49. // Operations
  50. // Access
  51. MsRsaPublicKeyBlob::ValueType const *
  52. MsRsaPublicKeyBlob::Data() const
  53. {
  54. return reinterpret_cast<ValueType const *>(MsRsaKeyBlob::Data());
  55. }
  56. MsRsaPublicKeyBlob::ElementValueType const *
  57. MsRsaPublicKeyBlob::Modulus() const
  58. {
  59. return reinterpret_cast<ElementValueType const *>(MsRsaKeyBlob::Data() + 1);
  60. }
  61. // Predicates
  62. // Static Variables
  63. /////////////////////////// PROTECTED /////////////////////////////////
  64. // C'tors/D'tors
  65. MsRsaPublicKeyBlob::MsRsaPublicKeyBlob(KeyBlobType kbt,
  66. ALG_ID algid,
  67. Blob const &rblbRawExponent,
  68. Blob const &rblbRawModulus,
  69. SizeType cReserve)
  70. : MsRsaKeyBlob(kbt, algid, Strength(rblbRawModulus.length()),
  71. rblbRawExponent,
  72. Reserve(rblbRawModulus.length()) + cReserve)
  73. {
  74. Init(rblbRawModulus);
  75. }
  76. // Operators
  77. // Operations
  78. // Access
  79. // Predicates
  80. // Static Variables
  81. /////////////////////////// PRIVATE /////////////////////////////////
  82. // C'tors/D'tors
  83. // Operators
  84. // Operations
  85. void
  86. MsRsaPublicKeyBlob::Init(Blob const &rblbRawModulus)
  87. {
  88. Append(rblbRawModulus.data(), rblbRawModulus.length());
  89. }
  90. // Access
  91. // Predicates
  92. // Static Variables