Diff

Differences From Artifact [d808ad3525]:

To Artifact [b4f2f9070a]:


   199    199   
   200    200   	if (outbuf) {
   201    201   		*outbuf = x509.serial_number.asn1rep;
   202    202   	}
   203    203   
   204    204   	return(x509.serial_number.asn1rep_len);
   205    205   }
          206  +
          207  +ssize_t x509_to_modulus(void *x509_der_buf, size_t x509_der_buf_len, void **outbuf) {
          208  +	struct asn1_object null, pubkey, modulus, exponent;
          209  +	struct x509_object x509;
          210  +	int read_ret;
          211  +
          212  +	read_ret = asn1_x509_read_object(x509_der_buf, x509_der_buf_len, &x509);
          213  +	if (read_ret != 0) {
          214  +		return(-1);
          215  +	}
          216  +
          217  +	/* The structure of "pubkey" is specified in PKCS #1 */
          218  +	read_ret = asn1_x509_read_asn1_object(x509.pubkey.contents, x509.pubkey.size, &null, &pubkey, NULL);
          219  +	if (read_ret != 0) {
          220  +		return(-1);
          221  +	}
          222  +
          223  +	read_ret = asn1_x509_read_asn1_object(pubkey.contents, pubkey.size, &modulus, &exponent, NULL);
          224  +	if (read_ret != 0) {
          225  +		return(-1);
          226  +	}
          227  +
          228  +	if (outbuf) {
          229  +		*outbuf = modulus.contents;
          230  +	}
          231  +
          232  +	return(modulus.size);
          233  +}
          234  +
          235  +ssize_t x509_to_exponent(void *x509_der_buf, size_t x509_der_buf_len, void **outbuf) {
          236  +	struct asn1_object null, pubkey, modulus, exponent;
          237  +	struct x509_object x509;
          238  +	int read_ret;
          239  +
          240  +	read_ret = asn1_x509_read_object(x509_der_buf, x509_der_buf_len, &x509);
          241  +	if (read_ret != 0) {
          242  +		return(-1);
          243  +	}
          244  +
          245  +	/* The structure of "pubkey" is specified in PKCS #1 */
          246  +	read_ret = asn1_x509_read_asn1_object(x509.pubkey.contents, x509.pubkey.size, &null, &pubkey, NULL);
          247  +	if (read_ret != 0) {
          248  +		return(-1);
          249  +	}
          250  +
          251  +	read_ret = asn1_x509_read_asn1_object(pubkey.contents, pubkey.size, &modulus, &exponent, NULL);
          252  +	if (read_ret != 0) {
          253  +		return(-1);
          254  +	}
          255  +
          256  +	if (outbuf) {
          257  +		*outbuf = exponent.contents;
          258  +	}
          259  +
          260  +	return(exponent.size);
          261  +}
   206    262   
   207    263   ssize_t x509_to_keysize(void *x509_der_buf, size_t x509_der_buf_len) {
   208    264   	struct asn1_object null, pubkey, modulus, exponent;
   209    265   	struct x509_object x509;
   210    266   	int read_ret;
   211    267   
   212    268   	read_ret = asn1_x509_read_object(x509_der_buf, x509_der_buf_len, &x509);