comparison libtomcrypt/src/pk/asn1/der/object_identifier/der_encode_object_identifier.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file der_encode_object_identifier.c 12 @file der_encode_object_identifier.c
53 wordbuf = words[y + 1]; 51 wordbuf = words[y + 1];
54 } 52 }
55 } 53 }
56 54
57 /* store header + length */ 55 /* store header + length */
58 x = 0; 56 x = 0;
59 out[x++] = 0x06; 57 out[x++] = 0x06;
60 if (z < 128) { 58 if (z < 128) {
61 out[x++] = (unsigned char)z; 59 out[x++] = (unsigned char)z;
62 } else if (z < 256) { 60 } else if (z < 256) {
63 out[x++] = 0x81; 61 out[x++] = 0x81;
69 } else { 67 } else {
70 return CRYPT_INVALID_ARG; 68 return CRYPT_INVALID_ARG;
71 } 69 }
72 70
73 /* store first byte */ 71 /* store first byte */
74 wordbuf = words[0] * 40 + words[1]; 72 wordbuf = words[0] * 40 + words[1];
75 for (i = 1; i < nwords; i++) { 73 for (i = 1; i < nwords; i++) {
76 /* store 7 bit words in little endian */ 74 /* store 7 bit words in little endian */
77 t = wordbuf & 0xFFFFFFFF; 75 t = wordbuf & 0xFFFFFFFF;
78 if (t) { 76 if (t) {
79 y = x; 77 y = x;
80 mask = 0; 78 mask = 0;
81 while (t) { 79 while (t) {
82 out[x++] = (unsigned char)((t & 0x7F) | mask); 80 out[x++] = (unsigned char)((t & 0x7F) | mask);
83 t >>= 7; 81 t >>= 7;
84 mask |= 0x80; /* upper bit is set on all but the last byte */ 82 mask |= 0x80; /* upper bit is set on all but the last byte */
85 } 83 }
86 /* now swap bytes y...x-1 */ 84 /* now swap bytes y...x-1 */
87 z = x - 1; 85 z = x - 1;
88 while (y < z) { 86 while (y < z) {
89 t = out[y]; out[y] = out[z]; out[z] = (unsigned char)t; 87 t = out[y]; out[y] = out[z]; out[z] = (unsigned char)t;
90 ++y; 88 ++y;
91 --z; 89 --z;
92 } 90 }
93 } else { 91 } else {
94 /* zero word */ 92 /* zero word */
95 out[x++] = 0x00; 93 out[x++] = 0x00;
96 } 94 }
97 95
98 if (i < nwords - 1) { 96 if (i < nwords - 1) {
99 wordbuf = words[i + 1]; 97 wordbuf = words[i + 1];
100 } 98 }
101 } 99 }
102 100
103 *outlen = x; 101 *outlen = x;
104 return CRYPT_OK; 102 return CRYPT_OK;
105 } 103 }
106 104
107 #endif 105 #endif
108 106
109 /* $Source$ */ 107 /* ref: $Format:%D$ */
110 /* $Revision$ */ 108 /* git commit: $Format:%H$ */
111 /* $Date$ */ 109 /* commit time: $Format:%ai$ */