1dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/* rsa.c 2dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** 335d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker** Copyright 2012, The Android Open Source Project 4dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** 5dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** Redistribution and use in source and binary forms, with or without 6dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** modification, are permitted provided that the following conditions are met: 7dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** * Redistributions of source code must retain the above copyright 8dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** notice, this list of conditions and the following disclaimer. 9dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** * Redistributions in binary form must reproduce the above copyright 10dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** notice, this list of conditions and the following disclaimer in the 11dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** documentation and/or other materials provided with the distribution. 12dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** * Neither the name of Google Inc. nor the names of its contributors may 13dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** be used to endorse or promote products derived from this software 14dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** without specific prior written permission. 15dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** 1635d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker** THIS SOFTWARE IS PROVIDED BY Google Inc. ``AS IS'' AND ANY EXPRESS OR 17dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1835d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** EVENT SHALL Google Inc. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2135d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 2235d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2335d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project*/ 27dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project 28dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include "mincrypt/rsa.h" 29dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project 3035d9ad5ae72de846967b91aed97060f0e8558661Doug Zongkerint RSA_e_f4_verify(const RSAPublicKey* key, 3135d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker const uint8_t* signature, 3235d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker const int len, 3335d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker const uint8_t* sha); 34dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project 3535d9ad5ae72de846967b91aed97060f0e8558661Doug Zongkerint RSA_e_3_verify(const RSAPublicKey *key, 3635d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker const uint8_t *signature, 3735d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker const int len, 3835d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker const uint8_t *sha); 39dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project 40dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint RSA_verify(const RSAPublicKey *key, 41dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project const uint8_t *signature, 42dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project const int len, 43dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project const uint8_t *sha) { 4435d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker switch (key->exponent) { 4535d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker case 3: 4635d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker return RSA_e_3_verify(key, signature, len, sha); 4735d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker break; 4835d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker case 65537: 4935d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker return RSA_e_f4_verify(key, signature, len, sha); 5035d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker break; 5135d9ad5ae72de846967b91aed97060f0e8558661Doug Zongker default: 52dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project return 0; 53dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project } 54dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project} 55