AuthCode.c 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /******************************************************************
  2. ******************************************************************
  3. *** **
  4. *** (C)Copyright 2008-2009, American Megatrends Inc. **
  5. *** **
  6. *** All Rights Reserved. **
  7. *** **
  8. *** 5555 , Oakbrook Pkwy, Norcross, **
  9. *** **
  10. *** Georgia - 30093, USA. Phone-(770)-246-8600. **
  11. *** **
  12. ******************************************************************
  13. ******************************************************************
  14. ******************************************************************
  15. *
  16. * AuthCode.c
  17. * Authentication Code Caluculation
  18. *
  19. * Author: Winston <winstonv@amiindia.co.in>
  20. ******************************************************************/
  21. #include "RMCP.h"
  22. #include "MD.h"
  23. #include <string.h>
  24. #include <stdint.h>
  25. #include "com_IPMIDefs.h"
  26. #include "com_IPMI_RMCP.h"
  27. #include "com_IPMI_AppDevice.h"
  28. #include "Session.h"
  29. /**
  30. * @fn ComputeAuthCode
  31. * @brief Compute authentication code.
  32. * @param pPassword - User password.
  33. * @param pSessionHdr - Session header RMCP message.
  34. * @param pIPMIMsg - IPMI message payload.
  35. * @param pAuthCode - Authentication Code being generated.
  36. * @param ChannelType - Channel Type.
  37. **/
  38. void
  39. ComputeAuthCode ( uint8_t* pPassword, SessionHdr_T* pSessionHdr,
  40. IPMIMsgHdr_T* pIPMIMsg, uint8_t* pAuthCode,
  41. uint8_t ChannelType)
  42. {
  43. if (AUTH_TYPE_PASSWORD == pSessionHdr->AuthType)
  44. {
  45. memcpy (pAuthCode, pPassword, IPMI15_MAX_PASSWORD_LEN);
  46. }
  47. else
  48. {
  49. uint8_t AuthBuf [MAX_AUTH_PARAM_SIZE];
  50. uint16_t AuthBufLen = 0;
  51. uint8_t IPMIMsgLen = *(( uint8_t*) pIPMIMsg - 1);
  52. /* Password */
  53. memcpy (AuthBuf, pPassword, IPMI15_MAX_PASSWORD_LEN);
  54. AuthBufLen += IPMI15_MAX_PASSWORD_LEN;
  55. /* Session ID */
  56. memcpy ((uint8_t*)(AuthBuf + AuthBufLen), (uint8_t*)(&pSessionHdr->SessionID), sizeof (uint32_t));
  57. AuthBufLen += sizeof (uint32_t);
  58. /* IPMI Response Message */
  59. memcpy (AuthBuf + AuthBufLen, pIPMIMsg, IPMIMsgLen);
  60. AuthBufLen += IPMIMsgLen;
  61. if (ChannelType == MULTI_SESSION_CHANNEL)
  62. {
  63. /* Session Sequence Number */
  64. memcpy ((uint8_t*)(AuthBuf + AuthBufLen), (uint8_t*)(&pSessionHdr->SessionSeqNum), sizeof (uint32_t));
  65. AuthBufLen += sizeof (uint32_t);
  66. }
  67. /* Password */
  68. memcpy (AuthBuf + AuthBufLen, pPassword, IPMI15_MAX_PASSWORD_LEN);
  69. AuthBufLen += IPMI15_MAX_PASSWORD_LEN;
  70. switch (pSessionHdr->AuthType)
  71. {
  72. case AUTH_TYPE_MD2 :
  73. AuthCodeCalMD2 (AuthBuf, pAuthCode, AuthBufLen);
  74. break;
  75. case AUTH_TYPE_MD5 :
  76. AuthCodeCalMD5 (AuthBuf, pAuthCode, AuthBufLen);
  77. break;
  78. default :
  79. printf ("RMCP.c : Invalid Authentication Type \r\n");
  80. }
  81. }
  82. }