Home | History | Annotate | Download | only in crypto
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "crypto/rsa_private_key.h"
      6 
      7 #include "base/memory/scoped_ptr.h"
      8 #include "testing/gtest/include/gtest/gtest.h"
      9 
     10 // Generate random private keys with two different sizes. Reimport, then
     11 // export them again. We should get back the same exact bytes.
     12 TEST(RSAPrivateKeyUnitTest, InitRandomTest) {
     13   scoped_ptr<crypto::RSAPrivateKey> keypair1(
     14       crypto::RSAPrivateKey::Create(1024));
     15   scoped_ptr<crypto::RSAPrivateKey> keypair2(
     16       crypto::RSAPrivateKey::Create(2048));
     17   ASSERT_TRUE(keypair1.get());
     18   ASSERT_TRUE(keypair2.get());
     19 
     20   std::vector<uint8> privkey1;
     21   std::vector<uint8> privkey2;
     22   std::vector<uint8> pubkey1;
     23   std::vector<uint8> pubkey2;
     24 
     25   ASSERT_TRUE(keypair1->ExportPrivateKey(&privkey1));
     26   ASSERT_TRUE(keypair2->ExportPrivateKey(&privkey2));
     27   ASSERT_TRUE(keypair1->ExportPublicKey(&pubkey1));
     28   ASSERT_TRUE(keypair2->ExportPublicKey(&pubkey2));
     29 
     30   scoped_ptr<crypto::RSAPrivateKey> keypair3(
     31       crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(privkey1));
     32   scoped_ptr<crypto::RSAPrivateKey> keypair4(
     33       crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(privkey2));
     34   ASSERT_TRUE(keypair3.get());
     35   ASSERT_TRUE(keypair4.get());
     36 
     37   std::vector<uint8> privkey3;
     38   std::vector<uint8> privkey4;
     39   ASSERT_TRUE(keypair3->ExportPrivateKey(&privkey3));
     40   ASSERT_TRUE(keypair4->ExportPrivateKey(&privkey4));
     41 
     42   ASSERT_EQ(privkey1.size(), privkey3.size());
     43   ASSERT_EQ(privkey2.size(), privkey4.size());
     44   ASSERT_TRUE(0 == memcmp(&privkey1.front(), &privkey3.front(),
     45                           privkey1.size()));
     46   ASSERT_TRUE(0 == memcmp(&privkey2.front(), &privkey4.front(),
     47                           privkey2.size()));
     48 }
     49 
     50 
     51 // Verify that generated public keys look good. This test data was generated
     52 // with the openssl command line tool.
     53 TEST(RSAPrivateKeyUnitTest, PublicKeyTest) {
     54   const uint8 private_key_info[] = {
     55     0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30,
     56     0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
     57     0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
     58     0x02, 0x62, 0x30, 0x82, 0x02, 0x5e, 0x02, 0x01,
     59     0x00, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b,
     60     0x20, 0xdc, 0x7c, 0x9b, 0x0c, 0xdc, 0x51, 0x61,
     61     0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08,
     62     0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64,
     63     0x85, 0x7b, 0x0c, 0x04, 0x13, 0x3f, 0x8d, 0xf4,
     64     0xbc, 0x38, 0x0d, 0x49, 0xfe, 0x6b, 0xc4, 0x5a,
     65     0xb0, 0x40, 0x53, 0x3a, 0xd7, 0x66, 0x09, 0x0f,
     66     0x9e, 0x36, 0x74, 0x30, 0xda, 0x8a, 0x31, 0x4f,
     67     0x1f, 0x14, 0x50, 0xd7, 0xc7, 0x20, 0x94, 0x17,
     68     0xde, 0x4e, 0xb9, 0x57, 0x5e, 0x7e, 0x0a, 0xe5,
     69     0xb2, 0x65, 0x7a, 0x89, 0x4e, 0xb6, 0x47, 0xff,
     70     0x1c, 0xbd, 0xb7, 0x38, 0x13, 0xaf, 0x47, 0x85,
     71     0x84, 0x32, 0x33, 0xf3, 0x17, 0x49, 0xbf, 0xe9,
     72     0x96, 0xd0, 0xd6, 0x14, 0x6f, 0x13, 0x8d, 0xc5,
     73     0xfc, 0x2c, 0x72, 0xba, 0xac, 0xea, 0x7e, 0x18,
     74     0x53, 0x56, 0xa6, 0x83, 0xa2, 0xce, 0x93, 0x93,
     75     0xe7, 0x1f, 0x0f, 0xe6, 0x0f, 0x02, 0x03, 0x01,
     76     0x00, 0x01, 0x02, 0x81, 0x80, 0x03, 0x61, 0x89,
     77     0x37, 0xcb, 0xf2, 0x98, 0xa0, 0xce, 0xb4, 0xcb,
     78     0x16, 0x13, 0xf0, 0xe6, 0xaf, 0x5c, 0xc5, 0xa7,
     79     0x69, 0x71, 0xca, 0xba, 0x8d, 0xe0, 0x4d, 0xdd,
     80     0xed, 0xb8, 0x48, 0x8b, 0x16, 0x93, 0x36, 0x95,
     81     0xc2, 0x91, 0x40, 0x65, 0x17, 0xbd, 0x7f, 0xd6,
     82     0xad, 0x9e, 0x30, 0x28, 0x46, 0xe4, 0x3e, 0xcc,
     83     0x43, 0x78, 0xf9, 0xfe, 0x1f, 0x33, 0x23, 0x1e,
     84     0x31, 0x12, 0x9d, 0x3c, 0xa7, 0x08, 0x82, 0x7b,
     85     0x7d, 0x25, 0x4e, 0x5e, 0x19, 0xa8, 0x9b, 0xed,
     86     0x86, 0xb2, 0xcb, 0x3c, 0xfe, 0x4e, 0xa1, 0xfa,
     87     0x62, 0x87, 0x3a, 0x17, 0xf7, 0x60, 0xec, 0x38,
     88     0x29, 0xe8, 0x4f, 0x34, 0x9f, 0x76, 0x9d, 0xee,
     89     0xa3, 0xf6, 0x85, 0x6b, 0x84, 0x43, 0xc9, 0x1e,
     90     0x01, 0xff, 0xfd, 0xd0, 0x29, 0x4c, 0xfa, 0x8e,
     91     0x57, 0x0c, 0xc0, 0x71, 0xa5, 0xbb, 0x88, 0x46,
     92     0x29, 0x5c, 0xc0, 0x4f, 0x01, 0x02, 0x41, 0x00,
     93     0xf5, 0x83, 0xa4, 0x64, 0x4a, 0xf2, 0xdd, 0x8c,
     94     0x2c, 0xed, 0xa8, 0xd5, 0x60, 0x5a, 0xe4, 0xc7,
     95     0xcc, 0x61, 0xcd, 0x38, 0x42, 0x20, 0xd3, 0x82,
     96     0x18, 0xf2, 0x35, 0x00, 0x72, 0x2d, 0xf7, 0x89,
     97     0x80, 0x67, 0xb5, 0x93, 0x05, 0x5f, 0xdd, 0x42,
     98     0xba, 0x16, 0x1a, 0xea, 0x15, 0xc6, 0xf0, 0xb8,
     99     0x8c, 0xbc, 0xbf, 0x54, 0x9e, 0xf1, 0xc1, 0xb2,
    100     0xb3, 0x8b, 0xb6, 0x26, 0x02, 0x30, 0xc4, 0x81,
    101     0x02, 0x41, 0x00, 0xc0, 0x60, 0x62, 0x80, 0xe1,
    102     0x22, 0x78, 0xf6, 0x9d, 0x83, 0x18, 0xeb, 0x72,
    103     0x45, 0xd7, 0xc8, 0x01, 0x7f, 0xa9, 0xca, 0x8f,
    104     0x7d, 0xd6, 0xb8, 0x31, 0x2b, 0x84, 0x7f, 0x62,
    105     0xd9, 0xa9, 0x22, 0x17, 0x7d, 0x06, 0x35, 0x6c,
    106     0xf3, 0xc1, 0x94, 0x17, 0x85, 0x5a, 0xaf, 0x9c,
    107     0x5c, 0x09, 0x3c, 0xcf, 0x2f, 0x44, 0x9d, 0xb6,
    108     0x52, 0x68, 0x5f, 0xf9, 0x59, 0xc8, 0x84, 0x2b,
    109     0x39, 0x22, 0x8f, 0x02, 0x41, 0x00, 0xb2, 0x04,
    110     0xe2, 0x0e, 0x56, 0xca, 0x03, 0x1a, 0xc0, 0xf9,
    111     0x12, 0x92, 0xa5, 0x6b, 0x42, 0xb8, 0x1c, 0xda,
    112     0x4d, 0x93, 0x9d, 0x5f, 0x6f, 0xfd, 0xc5, 0x58,
    113     0xda, 0x55, 0x98, 0x74, 0xfc, 0x28, 0x17, 0x93,
    114     0x1b, 0x75, 0x9f, 0x50, 0x03, 0x7f, 0x7e, 0xae,
    115     0xc8, 0x95, 0x33, 0x75, 0x2c, 0xd6, 0xa4, 0x35,
    116     0xb8, 0x06, 0x03, 0xba, 0x08, 0x59, 0x2b, 0x17,
    117     0x02, 0xdc, 0x4c, 0x7a, 0x50, 0x01, 0x02, 0x41,
    118     0x00, 0x9d, 0xdb, 0x39, 0x59, 0x09, 0xe4, 0x30,
    119     0xa0, 0x24, 0xf5, 0xdb, 0x2f, 0xf0, 0x2f, 0xf1,
    120     0x75, 0x74, 0x0d, 0x5e, 0xb5, 0x11, 0x73, 0xb0,
    121     0x0a, 0xaa, 0x86, 0x4c, 0x0d, 0xff, 0x7e, 0x1d,
    122     0xb4, 0x14, 0xd4, 0x09, 0x91, 0x33, 0x5a, 0xfd,
    123     0xa0, 0x58, 0x80, 0x9b, 0xbe, 0x78, 0x2e, 0x69,
    124     0x82, 0x15, 0x7c, 0x72, 0xf0, 0x7b, 0x18, 0x39,
    125     0xff, 0x6e, 0xeb, 0xc6, 0x86, 0xf5, 0xb4, 0xc7,
    126     0x6f, 0x02, 0x41, 0x00, 0x8d, 0x1a, 0x37, 0x0f,
    127     0x76, 0xc4, 0x82, 0xfa, 0x5c, 0xc3, 0x79, 0x35,
    128     0x3e, 0x70, 0x8a, 0xbf, 0x27, 0x49, 0xb0, 0x99,
    129     0x63, 0xcb, 0x77, 0x5f, 0xa8, 0x82, 0x65, 0xf6,
    130     0x03, 0x52, 0x51, 0xf1, 0xae, 0x2e, 0x05, 0xb3,
    131     0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb,
    132     0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca,
    133     0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3,
    134     0xb1, 0xc5, 0x15, 0xf3
    135   };
    136 
    137   const uint8 expected_public_key_info[] = {
    138     0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a,
    139     0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
    140     0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81,
    141     0x89, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b,
    142     0x20, 0xdc, 0x7c, 0x9b, 0x0c, 0xdc, 0x51, 0x61,
    143     0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08,
    144     0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64,
    145     0x85, 0x7b, 0x0c, 0x04, 0x13, 0x3f, 0x8d, 0xf4,
    146     0xbc, 0x38, 0x0d, 0x49, 0xfe, 0x6b, 0xc4, 0x5a,
    147     0xb0, 0x40, 0x53, 0x3a, 0xd7, 0x66, 0x09, 0x0f,
    148     0x9e, 0x36, 0x74, 0x30, 0xda, 0x8a, 0x31, 0x4f,
    149     0x1f, 0x14, 0x50, 0xd7, 0xc7, 0x20, 0x94, 0x17,
    150     0xde, 0x4e, 0xb9, 0x57, 0x5e, 0x7e, 0x0a, 0xe5,
    151     0xb2, 0x65, 0x7a, 0x89, 0x4e, 0xb6, 0x47, 0xff,
    152     0x1c, 0xbd, 0xb7, 0x38, 0x13, 0xaf, 0x47, 0x85,
    153     0x84, 0x32, 0x33, 0xf3, 0x17, 0x49, 0xbf, 0xe9,
    154     0x96, 0xd0, 0xd6, 0x14, 0x6f, 0x13, 0x8d, 0xc5,
    155     0xfc, 0x2c, 0x72, 0xba, 0xac, 0xea, 0x7e, 0x18,
    156     0x53, 0x56, 0xa6, 0x83, 0xa2, 0xce, 0x93, 0x93,
    157     0xe7, 0x1f, 0x0f, 0xe6, 0x0f, 0x02, 0x03, 0x01,
    158     0x00, 0x01
    159   };
    160 
    161   std::vector<uint8> input;
    162   input.resize(sizeof(private_key_info));
    163   memcpy(&input.front(), private_key_info, sizeof(private_key_info));
    164 
    165   scoped_ptr<crypto::RSAPrivateKey> key(
    166       crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input));
    167   ASSERT_TRUE(key.get());
    168 
    169   std::vector<uint8> output;
    170   ASSERT_TRUE(key->ExportPublicKey(&output));
    171 
    172   ASSERT_TRUE(
    173       memcmp(expected_public_key_info, &output.front(), output.size()) == 0);
    174 }
    175 
    176 // These two test keys each contain an integer that has 0x00 for its most
    177 // significant byte. When encoded as ASN.1, this byte is dropped and there are
    178 // two interesting sub-cases. When the sign bit of the integer is set, an extra
    179 // null byte is added back to force the encoded value to be positive. When the
    180 // sign bit is not set, the encoded integer is just left shorter than usual.
    181 // See also: http://code.google.com/p/chromium/issues/detail?id=14877.
    182 //
    183 // Before we were handling this correctly, we would see one of two failures:
    184 // * RSAPrivateKey::CreateFromPrivateKeyInfo would return null because the
    185 //   underlying windows API failed to import the key.
    186 // * The import would succeed, but incorrectly interpret the data. On export,
    187 //   the key would contain different values.
    188 //
    189 // This test case verifies these two failures modes don't occur.
    190 TEST(RSAPrivateKeyUnitTest, ShortIntegers) {
    191   const uint8 short_integer_with_high_bit[] = {
    192     0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x00, 0x30,
    193     0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
    194     0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
    195     0x02, 0x61, 0x30, 0x82, 0x02, 0x5d, 0x02, 0x01,
    196     0x00, 0x02, 0x81, 0x81, 0x00, 0x92, 0x59, 0x32,
    197     0x7d, 0x8e, 0xaf, 0x2e, 0xd5, 0xb2, 0x5c, 0x67,
    198     0xc8, 0x7d, 0x48, 0xb7, 0x84, 0x12, 0xd0, 0x76,
    199     0xda, 0xe1, 0xa3, 0x1e, 0x40, 0x01, 0x14, 0x5c,
    200     0xef, 0x26, 0x6e, 0x28, 0xa2, 0xf7, 0xa5, 0xb4,
    201     0x02, 0x37, 0xd0, 0x53, 0x10, 0xcb, 0x7c, 0x6a,
    202     0xf4, 0x53, 0x9f, 0xb8, 0xe0, 0x83, 0x93, 0xd1,
    203     0x19, 0xd8, 0x28, 0xd1, 0xd1, 0xd8, 0x87, 0x8f,
    204     0x92, 0xfd, 0x73, 0xc0, 0x4d, 0x3e, 0x07, 0x22,
    205     0x1f, 0xc1, 0x20, 0xb0, 0x70, 0xb2, 0x3b, 0xea,
    206     0xb1, 0xe5, 0x0a, 0xfd, 0x56, 0x49, 0x5e, 0x39,
    207     0x90, 0x91, 0xce, 0x04, 0x83, 0x29, 0xaa, 0xfd,
    208     0x12, 0xa4, 0x42, 0x26, 0x6c, 0x6e, 0x79, 0x70,
    209     0x77, 0x03, 0xb2, 0x07, 0x01, 0x3d, 0x85, 0x81,
    210     0x95, 0x9e, 0xda, 0x5a, 0xa3, 0xf4, 0x2d, 0x38,
    211     0x04, 0x58, 0xf5, 0x6b, 0xc9, 0xf1, 0xb5, 0x65,
    212     0xfe, 0x66, 0x0d, 0xa2, 0xd5, 0x02, 0x03, 0x01,
    213     0x00, 0x01, 0x02, 0x81, 0x80, 0x5e, 0x01, 0x5f,
    214     0xb6, 0x59, 0x1d, 0xdc, 0x36, 0xb6, 0x60, 0x36,
    215     0xe6, 0x08, 0xdb, 0xd9, 0xcd, 0xc3, 0x8c, 0x16,
    216     0x9c, 0x98, 0x8d, 0x7f, 0xd3, 0xdb, 0x1d, 0xaa,
    217     0x68, 0x8f, 0xc5, 0xf8, 0xe2, 0x5d, 0xb3, 0x19,
    218     0xc2, 0xc6, 0xf9, 0x51, 0x32, 0x1b, 0x93, 0x6a,
    219     0xdc, 0x50, 0x8e, 0xeb, 0x61, 0x84, 0x03, 0x42,
    220     0x30, 0x98, 0xb1, 0xf7, 0xbd, 0x14, 0x9a, 0x57,
    221     0x36, 0x33, 0x09, 0xd4, 0x3e, 0x90, 0xda, 0xef,
    222     0x09, 0x6e, 0xef, 0x49, 0xb6, 0x60, 0x68, 0x5e,
    223     0x54, 0x17, 0x25, 0x5b, 0x37, 0xe3, 0x35, 0x63,
    224     0x5b, 0x60, 0x3c, 0xbd, 0x50, 0xdf, 0x46, 0x43,
    225     0x08, 0xa4, 0x71, 0x21, 0xf1, 0x30, 0x71, 0xdc,
    226     0xda, 0xd7, 0x6f, 0xd2, 0x18, 0xbd, 0x39, 0xf1,
    227     0xe1, 0xbe, 0xa8, 0x8d, 0x62, 0xdf, 0xa2, 0x3e,
    228     0xb6, 0x15, 0x26, 0xb6, 0x57, 0xbd, 0x63, 0xdb,
    229     0xc1, 0x91, 0xec, 0xb8, 0x01, 0x02, 0x41, 0x00,
    230     0xc6, 0x1a, 0x06, 0x48, 0xf2, 0x12, 0x1c, 0x9f,
    231     0x74, 0x20, 0x5c, 0x85, 0xa2, 0xda, 0xe5, 0x62,
    232     0x96, 0x8d, 0x22, 0x7b, 0x78, 0x73, 0xea, 0xbb,
    233     0x9f, 0x59, 0x42, 0x13, 0x15, 0xc8, 0x11, 0x50,
    234     0x6c, 0x55, 0xf6, 0xdf, 0x8b, 0xfe, 0xc7, 0xdd,
    235     0xa8, 0xca, 0x54, 0x41, 0xe8, 0xce, 0xbe, 0x7d,
    236     0xbd, 0xe2, 0x13, 0x4b, 0x5b, 0x61, 0xeb, 0x69,
    237     0x6c, 0xb1, 0x9b, 0x28, 0x68, 0x5b, 0xd6, 0x01,
    238     0x02, 0x41, 0x00, 0xbd, 0x1e, 0xfe, 0x51, 0x99,
    239     0xb6, 0xe3, 0x84, 0xfe, 0xf1, 0x9e, 0xfd, 0x9c,
    240     0xe7, 0x86, 0x43, 0x68, 0x7f, 0x2f, 0x6a, 0x2a,
    241     0x4c, 0xae, 0xa6, 0x41, 0x1c, 0xf0, 0x10, 0x37,
    242     0x54, 0x23, 0xba, 0x05, 0x0d, 0x18, 0x27, 0x8d,
    243     0xb8, 0xe4, 0x8f, 0xf2, 0x25, 0x73, 0x8a, 0xd7,
    244     0x05, 0x98, 0x6b, 0x3d, 0x55, 0xb7, 0x6f, 0x7c,
    245     0xec, 0x77, 0x61, 0x54, 0x7b, 0xb6, 0x6b, 0x31,
    246     0xec, 0x94, 0xd5, 0x02, 0x41, 0x00, 0x90, 0xa2,
    247     0xa5, 0x9e, 0x12, 0xa7, 0x68, 0xa0, 0x7e, 0xdf,
    248     0xb5, 0xcd, 0x98, 0x26, 0xab, 0xbd, 0xbc, 0x5f,
    249     0xd5, 0x22, 0x42, 0xc2, 0x97, 0x4a, 0x5f, 0x40,
    250     0x82, 0xfe, 0x7e, 0x33, 0xb1, 0x78, 0x7f, 0x70,
    251     0x90, 0x2b, 0x8d, 0x01, 0xfb, 0x18, 0xfa, 0x48,
    252     0xa7, 0x15, 0xec, 0x0d, 0x2e, 0x85, 0x8d, 0xe2,
    253     0x86, 0xe5, 0xc9, 0x15, 0x88, 0x14, 0x53, 0xd8,
    254     0xa4, 0x88, 0xef, 0x10, 0xc6, 0x01, 0x02, 0x41,
    255     0x00, 0xba, 0xe4, 0xaf, 0x14, 0xfa, 0xdf, 0xf6,
    256     0xd5, 0xce, 0x8f, 0xfe, 0xbb, 0xc8, 0x5c, 0x30,
    257     0x9d, 0xda, 0xdd, 0x9d, 0x80, 0xc0, 0x0e, 0x89,
    258     0xa5, 0xb8, 0xc1, 0x1d, 0x28, 0x19, 0x55, 0x67,
    259     0xfd, 0x03, 0xd2, 0xdd, 0xe4, 0xf0, 0xb4, 0x20,
    260     0x03, 0x74, 0x9b, 0xb8, 0x24, 0x23, 0xbb, 0xde,
    261     0xd5, 0x53, 0x86, 0xaa, 0xc1, 0x5d, 0x65, 0xdd,
    262     0xcf, 0xec, 0x8a, 0x59, 0x4a, 0x73, 0xca, 0xc5,
    263     0x85, 0x02, 0x40, 0x00, 0xc4, 0x5e, 0x8d, 0xa4,
    264     0xea, 0xbb, 0x6a, 0x9b, 0xe6, 0x3a, 0x4d, 0xc1,
    265     0xdb, 0xe5, 0x52, 0x38, 0xf9, 0x59, 0x91, 0x2d,
    266     0x90, 0x82, 0xe3, 0x31, 0x1b, 0x48, 0xb7, 0x42,
    267     0xfa, 0x1d, 0x83, 0xd5, 0x3d, 0x02, 0xc2, 0x12,
    268     0x71, 0x10, 0x3a, 0xbd, 0x92, 0x8f, 0x9b, 0xa2,
    269     0x6b, 0x2d, 0x21, 0xa4, 0x65, 0xe9, 0xfa, 0x8c,
    270     0x30, 0x2a, 0x89, 0xce, 0xd0, 0xa7, 0x67, 0xd8,
    271     0x45, 0x84, 0xb0
    272   };
    273 
    274   const uint8 short_integer_without_high_bit[] = {
    275     0x30, 0x82, 0x02, 0x76, 0x02, 0x01, 0x00, 0x30,
    276     0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
    277     0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
    278     0x02, 0x60, 0x30, 0x82, 0x02, 0x5c, 0x02, 0x01,
    279     0x00, 0x02, 0x81, 0x81, 0x00, 0xc3, 0x9e, 0x8d,
    280     0xc4, 0x6d, 0x38, 0xe8, 0x0e, 0x9f, 0x84, 0x03,
    281     0x40, 0x8e, 0x81, 0x2e, 0x56, 0x67, 0x78, 0x11,
    282     0x85, 0x27, 0x81, 0x52, 0xf2, 0x1b, 0x3e, 0x5b,
    283     0xf8, 0xab, 0xfc, 0xaf, 0xca, 0x5c, 0x26, 0xd5,
    284     0xfa, 0xd4, 0x55, 0x50, 0x38, 0xb9, 0x9d, 0x89,
    285     0x92, 0x7e, 0x34, 0xcf, 0x37, 0x82, 0x48, 0x2d,
    286     0xaa, 0xc4, 0x6a, 0x0e, 0x93, 0xea, 0xad, 0x8a,
    287     0x33, 0xf0, 0x42, 0x23, 0xe0, 0x4c, 0x98, 0xbf,
    288     0x01, 0x00, 0x1b, 0xfe, 0x06, 0x15, 0xc6, 0xe3,
    289     0x80, 0x79, 0x6d, 0xfe, 0x48, 0xcd, 0x40, 0xbb,
    290     0xf9, 0x58, 0xe6, 0xbf, 0xd5, 0x4c, 0x29, 0x48,
    291     0x53, 0x78, 0x06, 0x03, 0x0d, 0x59, 0xf5, 0x20,
    292     0xe0, 0xe6, 0x8c, 0xb2, 0xf5, 0xd8, 0x61, 0x52,
    293     0x7e, 0x40, 0x83, 0xd7, 0x69, 0xae, 0xd7, 0x75,
    294     0x02, 0x2d, 0x49, 0xd5, 0x15, 0x5b, 0xf1, 0xd9,
    295     0x4d, 0x60, 0x7d, 0x62, 0xa5, 0x02, 0x03, 0x01,
    296     0x00, 0x01, 0x02, 0x7f, 0x6d, 0x45, 0x23, 0xeb,
    297     0x95, 0x17, 0x34, 0x88, 0xf6, 0x91, 0xc7, 0x3f,
    298     0x48, 0x5a, 0xe0, 0x87, 0x63, 0x44, 0xae, 0x84,
    299     0xb2, 0x8c, 0x8a, 0xc8, 0xb2, 0x6f, 0x22, 0xf0,
    300     0xc5, 0x21, 0x61, 0x10, 0xa8, 0x69, 0x09, 0x1e,
    301     0x13, 0x7d, 0x94, 0x52, 0x1b, 0x5c, 0xe4, 0x7b,
    302     0xf0, 0x03, 0x8f, 0xbc, 0x72, 0x09, 0xdf, 0x78,
    303     0x84, 0x3e, 0xb9, 0xe5, 0xe6, 0x31, 0x0a, 0x01,
    304     0xf9, 0x32, 0xf8, 0xd6, 0x57, 0xa3, 0x87, 0xe6,
    305     0xf5, 0x98, 0xbc, 0x8e, 0x41, 0xb9, 0x50, 0x17,
    306     0x7b, 0xd3, 0x97, 0x5a, 0x44, 0x3a, 0xee, 0xff,
    307     0x6b, 0xb3, 0x3a, 0x52, 0xe7, 0xa4, 0x96, 0x9a,
    308     0xf6, 0x83, 0xc8, 0x97, 0x1c, 0x63, 0xa1, 0xd6,
    309     0xb3, 0xa8, 0xb2, 0xc7, 0x73, 0x25, 0x0f, 0x58,
    310     0x36, 0xb9, 0x7a, 0x47, 0xa7, 0x4d, 0x30, 0xfe,
    311     0x4d, 0x74, 0x56, 0xe8, 0xfb, 0xd6, 0x50, 0xe5,
    312     0xe0, 0x28, 0x15, 0x02, 0x41, 0x00, 0xeb, 0x15,
    313     0x62, 0xb6, 0x37, 0x41, 0x7c, 0xc5, 0x00, 0x22,
    314     0x2c, 0x5a, 0x5e, 0xe4, 0xb2, 0x11, 0x87, 0x89,
    315     0xad, 0xf4, 0x57, 0x68, 0x90, 0xb7, 0x9f, 0xe2,
    316     0x79, 0x20, 0x6b, 0x98, 0x00, 0x0d, 0x3a, 0x3b,
    317     0xc1, 0xcd, 0x36, 0xf9, 0x27, 0xda, 0x40, 0x36,
    318     0x1d, 0xb8, 0x5c, 0x96, 0xeb, 0x04, 0x08, 0xe1,
    319     0x3f, 0xfa, 0x94, 0x8b, 0x0f, 0xa0, 0xff, 0xc1,
    320     0x51, 0xea, 0x90, 0xad, 0x15, 0xc7, 0x02, 0x41,
    321     0x00, 0xd5, 0x06, 0x45, 0xd7, 0x55, 0x63, 0x1a,
    322     0xf0, 0x89, 0x81, 0xae, 0x87, 0x23, 0xa2, 0x39,
    323     0xfe, 0x3d, 0x82, 0xc7, 0xcb, 0x15, 0xb9, 0xe3,
    324     0xe2, 0x5b, 0xc6, 0xd2, 0x55, 0xdd, 0xab, 0x55,
    325     0x29, 0x7c, 0xda, 0x0e, 0x1c, 0x09, 0xfc, 0x73,
    326     0x0d, 0x01, 0xed, 0x6d, 0x2f, 0x05, 0xd0, 0xd5,
    327     0x1d, 0xce, 0x18, 0x7f, 0xb0, 0xc8, 0x47, 0x77,
    328     0xd2, 0xa9, 0x9e, 0xfc, 0x39, 0x4b, 0x3d, 0x94,
    329     0x33, 0x02, 0x41, 0x00, 0x8f, 0x94, 0x09, 0x2d,
    330     0x17, 0x44, 0x75, 0x0a, 0xf1, 0x10, 0xee, 0x1b,
    331     0xe7, 0xd7, 0x2f, 0xf6, 0xca, 0xdc, 0x49, 0x15,
    332     0x72, 0x09, 0x58, 0x51, 0xfe, 0x61, 0xd8, 0xee,
    333     0xf7, 0x27, 0xe7, 0xe8, 0x2c, 0x47, 0xf1, 0x0f,
    334     0x00, 0x63, 0x5e, 0x76, 0xcb, 0x3f, 0x02, 0x19,
    335     0xe6, 0xda, 0xfa, 0x01, 0x05, 0xd7, 0x65, 0x37,
    336     0x0b, 0x60, 0x7f, 0x94, 0x2a, 0x80, 0x8d, 0x22,
    337     0x81, 0x68, 0x65, 0x63, 0x02, 0x41, 0x00, 0xc2,
    338     0xd4, 0x18, 0xde, 0x47, 0x9e, 0xfb, 0x8d, 0x91,
    339     0x05, 0xc5, 0x3c, 0x9d, 0xcf, 0x8a, 0x60, 0xc7,
    340     0x9b, 0x2b, 0xe5, 0xc6, 0xba, 0x1b, 0xfc, 0xf3,
    341     0xd9, 0x54, 0x97, 0xe9, 0xc4, 0x00, 0x80, 0x90,
    342     0x4a, 0xd2, 0x6a, 0xbc, 0x8b, 0x62, 0x22, 0x3c,
    343     0x68, 0x0c, 0xda, 0xdb, 0xe3, 0xd2, 0x76, 0x8e,
    344     0xff, 0x03, 0x12, 0x09, 0x2a, 0xac, 0x21, 0x44,
    345     0xb7, 0x3e, 0x91, 0x9c, 0x09, 0xf6, 0xd7, 0x02,
    346     0x41, 0x00, 0xc0, 0xa1, 0xbb, 0x70, 0xdc, 0xf8,
    347     0xeb, 0x17, 0x61, 0xd4, 0x8c, 0x7c, 0x3b, 0x82,
    348     0x91, 0x58, 0xff, 0xf9, 0x19, 0xac, 0x3a, 0x73,
    349     0xa7, 0x20, 0xe5, 0x22, 0x02, 0xc4, 0xf6, 0xb9,
    350     0xb9, 0x43, 0x53, 0x35, 0x88, 0xe1, 0x05, 0xb6,
    351     0x43, 0x9b, 0x39, 0xc8, 0x04, 0x4d, 0x2b, 0x01,
    352     0xf7, 0xe6, 0x1b, 0x8d, 0x7e, 0x89, 0xe3, 0x43,
    353     0xd4, 0xf3, 0xab, 0x28, 0xd4, 0x5a, 0x1f, 0x20,
    354     0xea, 0xbe
    355   };
    356 
    357   std::vector<uint8> input1;
    358   std::vector<uint8> input2;
    359 
    360   input1.resize(sizeof(short_integer_with_high_bit));
    361   input2.resize(sizeof(short_integer_without_high_bit));
    362 
    363   memcpy(&input1.front(), short_integer_with_high_bit,
    364          sizeof(short_integer_with_high_bit));
    365   memcpy(&input2.front(), short_integer_without_high_bit,
    366          sizeof(short_integer_without_high_bit));
    367 
    368   scoped_ptr<crypto::RSAPrivateKey> keypair1(
    369       crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input1));
    370   scoped_ptr<crypto::RSAPrivateKey> keypair2(
    371       crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input2));
    372   ASSERT_TRUE(keypair1.get());
    373   ASSERT_TRUE(keypair2.get());
    374 
    375   std::vector<uint8> output1;
    376   std::vector<uint8> output2;
    377   ASSERT_TRUE(keypair1->ExportPrivateKey(&output1));
    378   ASSERT_TRUE(keypair2->ExportPrivateKey(&output2));
    379 
    380   ASSERT_EQ(input1.size(), output1.size());
    381   ASSERT_EQ(input2.size(), output2.size());
    382   ASSERT_TRUE(0 == memcmp(&output1.front(), &input1.front(),
    383                           input1.size()));
    384   ASSERT_TRUE(0 == memcmp(&output2.front(), &input2.front(),
    385                           input2.size()));
    386 }
    387