The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* rsa.c |
| 2 | ** |
Doug Zongker | 35d9ad5 | 2012-07-25 12:08:33 -0700 | [diff] [blame] | 3 | ** Copyright 2012, The Android Open Source Project |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 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 | ** |
Doug Zongker | 35d9ad5 | 2012-07-25 12:08:33 -0700 | [diff] [blame] | 16 | ** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 17 | ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
Doug Zongker | 35d9ad5 | 2012-07-25 12:08:33 -0700 | [diff] [blame] | 18 | ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 19 | ** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
Doug Zongker | 35d9ad5 | 2012-07-25 12:08:33 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 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 | |
| 28 | #include "mincrypt/rsa.h" |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 29 | |
Doug Zongker | 35d9ad5 | 2012-07-25 12:08:33 -0700 | [diff] [blame] | 30 | int RSA_e_f4_verify(const RSAPublicKey* key, |
| 31 | const uint8_t* signature, |
| 32 | const int len, |
Doug Zongker | 515e163 | 2013-04-10 09:22:02 -0700 | [diff] [blame^] | 33 | const uint8_t* hash, |
| 34 | const int hash_len); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 35 | |
Doug Zongker | 35d9ad5 | 2012-07-25 12:08:33 -0700 | [diff] [blame] | 36 | int RSA_e_3_verify(const RSAPublicKey *key, |
| 37 | const uint8_t *signature, |
| 38 | const int len, |
Doug Zongker | 515e163 | 2013-04-10 09:22:02 -0700 | [diff] [blame^] | 39 | const uint8_t *hash, |
| 40 | const int hash_len); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 41 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 42 | int RSA_verify(const RSAPublicKey *key, |
| 43 | const uint8_t *signature, |
| 44 | const int len, |
Doug Zongker | 515e163 | 2013-04-10 09:22:02 -0700 | [diff] [blame^] | 45 | const uint8_t *hash, |
| 46 | const int hash_len) { |
Doug Zongker | 35d9ad5 | 2012-07-25 12:08:33 -0700 | [diff] [blame] | 47 | switch (key->exponent) { |
| 48 | case 3: |
Doug Zongker | 515e163 | 2013-04-10 09:22:02 -0700 | [diff] [blame^] | 49 | return RSA_e_3_verify(key, signature, len, hash, hash_len); |
Doug Zongker | 35d9ad5 | 2012-07-25 12:08:33 -0700 | [diff] [blame] | 50 | break; |
| 51 | case 65537: |
Doug Zongker | 515e163 | 2013-04-10 09:22:02 -0700 | [diff] [blame^] | 52 | return RSA_e_f4_verify(key, signature, len, hash, hash_len); |
Doug Zongker | 35d9ad5 | 2012-07-25 12:08:33 -0700 | [diff] [blame] | 53 | break; |
| 54 | default: |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 55 | return 0; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 56 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 57 | } |