Mercurial > dropbear
comparison keyimport.c @ 241:c5d3ef11155f
* use own assertions which should get logged properly
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 05 Sep 2005 15:16:10 +0000 |
parents | 680a0bc9df0a |
children | ac890087b8c1 |
comparison
equal
deleted
inserted
replaced
238:e923801a7678 | 241:c5d3ef11155f |
---|---|
201 char out[100]; | 201 char out[100]; |
202 int n; | 202 int n; |
203 unsigned long outlen; | 203 unsigned long outlen; |
204 int rawcpl; | 204 int rawcpl; |
205 rawcpl = cpl * 3 / 4; | 205 rawcpl = cpl * 3 / 4; |
206 assert((unsigned int)cpl < sizeof(out)); | 206 dropbear_assert((unsigned int)cpl < sizeof(out)); |
207 | 207 |
208 while (datalen > 0) { | 208 while (datalen > 0) { |
209 n = (datalen < rawcpl ? datalen : rawcpl); | 209 n = (datalen < rawcpl ? datalen : rawcpl); |
210 outlen = sizeof(out); | 210 outlen = sizeof(out); |
211 base64_encode(data, n, out, &outlen); | 211 base64_encode(data, n, out, &outlen); |
712 if (key->dsskey != NULL) { | 712 if (key->dsskey != NULL) { |
713 keytype = DROPBEAR_SIGNKEY_DSS; | 713 keytype = DROPBEAR_SIGNKEY_DSS; |
714 } | 714 } |
715 #endif | 715 #endif |
716 | 716 |
717 assert(keytype != -1); | 717 dropbear_assert(keytype != -1); |
718 | 718 |
719 /* | 719 /* |
720 * Fetch the key blobs. | 720 * Fetch the key blobs. |
721 */ | 721 */ |
722 keyblob = buf_new(3000); | 722 keyblob = buf_new(3000); |
911 * plaintext to the next layer: it looks at the final byte, and | 911 * plaintext to the next layer: it looks at the final byte, and |
912 * then expects to find that many bytes at the end of the data | 912 * then expects to find that many bytes at the end of the data |
913 * with the same value. Those are all removed and the rest is | 913 * with the same value. Those are all removed and the rest is |
914 * returned. | 914 * returned. |
915 */ | 915 */ |
916 assert(pos == len); | 916 dropbear_assert(pos == len); |
917 while (pos < outlen) { | 917 while (pos < outlen) { |
918 outblob[pos++] = outlen - len; | 918 outblob[pos++] = outlen - len; |
919 } | 919 } |
920 | 920 |
921 /* | 921 /* |
1489 publen = pos; | 1489 publen = pos; |
1490 pos += put_mp(blob+pos, x.start, x.bytes); | 1490 pos += put_mp(blob+pos, x.start, x.bytes); |
1491 privlen = pos - publen; | 1491 privlen = pos - publen; |
1492 } | 1492 } |
1493 | 1493 |
1494 assert(privlen > 0); /* should have bombed by now if not */ | 1494 dropbear_assert(privlen > 0); /* should have bombed by now if not */ |
1495 | 1495 |
1496 retkey = snew(struct ssh2_userkey); | 1496 retkey = snew(struct ssh2_userkey); |
1497 retkey->alg = alg; | 1497 retkey->alg = alg; |
1498 retkey->data = alg->createkey(blob, publen, blob+publen, privlen); | 1498 retkey->data = alg->createkey(blob, publen, blob+publen, privlen); |
1499 if (!retkey->data) { | 1499 if (!retkey->data) { |
1555 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &d); | 1555 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &d); |
1556 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &p); | 1556 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &p); |
1557 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &q); | 1557 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &q); |
1558 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &iqmp); | 1558 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &iqmp); |
1559 | 1559 |
1560 assert(e.start && iqmp.start); /* can't go wrong */ | 1560 dropbear_assert(e.start && iqmp.start); /* can't go wrong */ |
1561 | 1561 |
1562 numbers[0] = e; | 1562 numbers[0] = e; |
1563 numbers[1] = d; | 1563 numbers[1] = d; |
1564 numbers[2] = n; | 1564 numbers[2] = n; |
1565 numbers[3] = iqmp; | 1565 numbers[3] = iqmp; |
1579 pos += ssh2_read_mpint(pubblob+pos, publen-pos, &g); | 1579 pos += ssh2_read_mpint(pubblob+pos, publen-pos, &g); |
1580 pos += ssh2_read_mpint(pubblob+pos, publen-pos, &y); | 1580 pos += ssh2_read_mpint(pubblob+pos, publen-pos, &y); |
1581 pos = 0; | 1581 pos = 0; |
1582 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &x); | 1582 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &x); |
1583 | 1583 |
1584 assert(y.start && x.start); /* can't go wrong */ | 1584 dropbear_assert(y.start && x.start); /* can't go wrong */ |
1585 | 1585 |
1586 numbers[0] = p; | 1586 numbers[0] = p; |
1587 numbers[1] = g; | 1587 numbers[1] = g; |
1588 numbers[2] = q; | 1588 numbers[2] = q; |
1589 numbers[3] = y; | 1589 numbers[3] = y; |
1591 | 1591 |
1592 nnumbers = 5; | 1592 nnumbers = 5; |
1593 initial_zero = 1; | 1593 initial_zero = 1; |
1594 type = "dl-modp{sign{dsa-nist-sha1},dh{plain}}"; | 1594 type = "dl-modp{sign{dsa-nist-sha1},dh{plain}}"; |
1595 } else { | 1595 } else { |
1596 assert(0); /* zoinks! */ | 1596 dropbear_assert(0); /* zoinks! */ |
1597 } | 1597 } |
1598 | 1598 |
1599 /* | 1599 /* |
1600 * Total size of key blob will be somewhere under 512 plus | 1600 * Total size of key blob will be somewhere under 512 plus |
1601 * combined length of integers. We'll calculate the more | 1601 * combined length of integers. We'll calculate the more |
1635 while (padding--) | 1635 while (padding--) |
1636 outblob[pos++] = random_byte(); | 1636 outblob[pos++] = random_byte(); |
1637 } | 1637 } |
1638 ciphertext = (char *)outblob+lenpos+4; | 1638 ciphertext = (char *)outblob+lenpos+4; |
1639 cipherlen = pos - (lenpos+4); | 1639 cipherlen = pos - (lenpos+4); |
1640 assert(!passphrase || cipherlen % 8 == 0); | 1640 dropbear_assert(!passphrase || cipherlen % 8 == 0); |
1641 /* Wrap up the encrypted blob string. */ | 1641 /* Wrap up the encrypted blob string. */ |
1642 PUT_32BIT(outblob+lenpos, cipherlen); | 1642 PUT_32BIT(outblob+lenpos, cipherlen); |
1643 /* And finally fill in the total length field. */ | 1643 /* And finally fill in the total length field. */ |
1644 PUT_32BIT(outblob+4, pos); | 1644 PUT_32BIT(outblob+4, pos); |
1645 | 1645 |
1646 assert(pos < outlen); | 1646 dropbear_assert(pos < outlen); |
1647 | 1647 |
1648 /* | 1648 /* |
1649 * Encrypt the key. | 1649 * Encrypt the key. |
1650 */ | 1650 */ |
1651 if (passphrase) { | 1651 if (passphrase) { |