rsa.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* rsa.c
  2. **
  3. ** Copyright 2012, The Android Open Source Project
  4. **
  5. ** Redistribution and use in source and binary forms, with or without
  6. ** modification, are permitted provided that the following conditions are met:
  7. ** * Redistributions of source code must retain the above copyright
  8. ** notice, this list of conditions and the following disclaimer.
  9. ** * Redistributions in binary form must reproduce the above copyright
  10. ** notice, this list of conditions and the following disclaimer in the
  11. ** documentation and/or other materials provided with the distribution.
  12. ** * Neither the name of Google Inc. nor the names of its contributors may
  13. ** be used to endorse or promote products derived from this software
  14. ** without specific prior written permission.
  15. **
  16. ** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR
  17. ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. ** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  21. ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  22. ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  23. ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  24. ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "mincrypt/rsa.h"
  28. int RSA_e_f4_verify(const RSAPublicKey* key,
  29. const uint8_t* signature,
  30. const int len,
  31. const uint8_t* sha);
  32. int RSA_e_3_verify(const RSAPublicKey *key,
  33. const uint8_t *signature,
  34. const int len,
  35. const uint8_t *sha);
  36. int RSA_verify(const RSAPublicKey *key,
  37. const uint8_t *signature,
  38. const int len,
  39. const uint8_t *sha) {
  40. switch (key->exponent) {
  41. case 3:
  42. return RSA_e_3_verify(key, signature, len, sha);
  43. break;
  44. case 65537:
  45. return RSA_e_f4_verify(key, signature, len, sha);
  46. break;
  47. default:
  48. return 0;
  49. }
  50. }