CM_PASSWORD.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Verify Password
  2. //
  3. // CryptoMemory Library Include Files
  4. #include "CM_LIB.h"
  5. #include "CM_I2C.h"
  6. #include "CM_I2C_L.h"
  7. #include "CM_GPA.h"
  8. uint8_t ucCmdPassword[4] = {0xba, 0x00, 0x00, 0x03};
  9. uint8_t ucPSW[3];
  10. // Verify Password
  11. uint8_t cm_VerifyPassword(uint8_t * pucPassword, uint8_t ucSet, uint8_t ucRW)
  12. {
  13. uint8_t i, j;
  14. uint8_t ucReturn;
  15. uint8_t ucAddr;
  16. // Build command and PAC address
  17. ucAddr = CM_PSW + (ucSet<<3);
  18. ucCmdPassword[1] = ucSet;// to choose which sets of passwords
  19. if (ucRW != CM_PWWRITE) {
  20. ucCmdPassword[1] |= 0x10;
  21. ucAddr += 4;
  22. }
  23. // Deal with encryption if in authenticate mode
  24. for (j = 0; j<3; j++) {
  25. // Encrypt the password
  26. if(ucCM_Authenticate) {
  27. for(i = 0; i<5; i++) cm_GPAGen(pucPassword[j]);
  28. ucPSW[j] = Gpa_byte;
  29. }
  30. // Else just copy it
  31. else ucPSW[j] = pucPassword[j];
  32. }
  33. // Send the command
  34. ucReturn = cm_WriteCommand(ucCmdPassword, ucPSW, 3);
  35. // Wait for chip to process password
  36. CM_LOW_LEVEL.WaitClock(3);
  37. // Read Password attempts counter to determine if the password was accepted
  38. if (ucReturn == SUCCESS) {
  39. ucReturn = cm_ReadConfigZone(ucAddr, ucPSW, 1);
  40. if (ucPSW[0]!= 0xFF) ucReturn = FAILED;
  41. }
  42. if (ucCM_Authenticate && (ucReturn != SUCCESS)) cm_ResetCrypto();
  43. // Done
  44. return ucReturn;
  45. }