i'm trying to convert ASN1_INTEGER (specifically certificate serial
number) into its DER representation.
I'm using i2c_ASN1_INTEGER - and if it's the right function - then I don't
understand why it moves a pointer passed to it as second parameter behind
reserved memory.
Here is what I'm doing:
int size;
ASN1_INTEGER * serial;
unsigned char * serialNumberDER;
size = i2c_ASN1_INTEGER(serial, NULL);
serialNumberDER = new unsigned char[*size];
size = i2c_ASN1_INTEGER(serial, & serialNumberDER);
The function has this code at the end:
*pp+=ret;
where pp is a pointer to serialNumberDER, so in effect it moves
serialNumberDER behind created array of unsigned char.
Please, explain it to me.
Thanks in advance.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openss...@openssl.org
Automated List Manager majo...@openssl.org
However, still I don't see any reason why this function increments its
second argument ? And why to the first byte after the DER-encoded INTEGER
(it's out of preallocated memory) ? If you please enlightened me I would
be grateful for.
Best regards
Andrzej
"Frank Balluffi" <frank.b...@db.com>
2004-02-11 14:41
To: aposi...@computerland.pl
cc: openss...@openssl.org
Subject: Re: How to convert internal ASN1_INTEGER into little endian content octets
Andrzej,
Call i2d_ASN1_INTEGER to DER-encode an ASN.1 INTEGER. Pass 0 or NULL as
the second argument to i2d_ASN1_INTEGER to determine the length of the
DER-encoded INTEGER. If you pass a non-zero value as the second argument
to i2d_ASN1_INTEGER, the function will DER-encode the INTEGER and
increment the second argument to the first byte after the DER-encoded
INTEGER. Looks like (I did not compile this code):
ASN1_INTEGER * integer; /* points to an ASN1_INTEGER */
unsigned char * der = NULL;
unsigned char * derNext = NULL;
int length = 0;
length = i2d_ASN1_INTEGER(integer, 0);
if (length <= 0)
goto error;
der = OPENSSL_malloc(length);
if (!der)
goto error;
/*
Because i2d functions modify their second argument, use the variable
derNext.
*/
derNext = der;
length = i2d_ASN1_INTEGER(integer, &derNext);
if (length <= 0)
goto error;
Frank
"Andrzej Posiadala" <aposi...@computerland.pl>
Sent by: owner-ope...@openssl.org
02/11/2004 07:57 AM
Please respond to openssl-users
To: openss...@openssl.org
cc:
Subject: How to convert internal ASN1_INTEGER into little
endian content octets
Andrzej,
length = i2d_ASN1_INTEGER(integer, 0);
der = OPENSSL_malloc(length);
if (!der)
goto error;
Frank
Hi ,
*pp+=ret;
--=_alternative 004B333985256E37_=
Content-Type: text/html; charset="us-ascii"
<br><font size=2><tt>Andrzej,</tt></font>
<br>
<br><font size=2><tt>Call i2d_ASN1_INTEGER to DER-encode an ASN.1 INTEGER. Pass 0 or NULL as the second argument to i2d_ASN1_INTEGER to determine the length of the DER-encoded INTEGER. If you pass a non-zero value as the second argument to i2d_ASN1_INTEGER, the function will DER-encode the INTEGER and increment the second argument to the first byte after the DER-encoded INTEGER. Looks like (I did not compile this code):</tt></font>
<br>
<br><font size=2><tt> ASN1_INTEGER * integer; /* points to an ASN1_INTEGER */</tt></font>
<br><font size=2><tt> unsigned char * der = NULL;</tt></font>
<br><font size=2><tt> unsigned char * derNext = NULL;</tt></font>
<br><font size=2><tt> int length = 0;</tt></font>
<br>
<br><font size=2><tt> length = i2d_ASN1_INTEGER(integer, 0);</tt></font>
<br>
<br><font size=2><tt> if (length <= 0)</tt></font>
<br><font size=2><tt> goto error;</tt></font>
<br>
<br><font size=2><tt> der = OPENSSL_malloc(length);</tt></font>
<br>
<br><font size=2><tt> if (!der)</tt></font>
<br><font size=2><tt> goto error;</tt></font>
<br>
<br><font size=2><tt> /*</tt></font>
<br><font size=2><tt> Because i2d functions modify their second argument, use the variable</tt></font>
<br><font size=2><tt> derNext.</tt></font>
<br><font size=2><tt> */</tt></font>
<br>
<br><font size=2><tt> derNext = der;</tt></font>
<br><font size=2><tt> length = i2d_ASN1_INTEGER(integer, &derNext);</tt></font>
<br>
<br><font size=2><tt> if (length <= 0)</tt></font>
<br><font size=2><tt> goto error;</tt></font>
<br>
<br><font size=2><tt>Frank</tt></font>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td>
<td><font size=1 face="sans-serif"><b>"Andrzej Posiadala" <aposi...@computerland.pl></b></font>
<br><font size=1 face="sans-serif">Sent by: owner-ope...@openssl.org</font>
<p><font size=1 face="sans-serif">02/11/2004 07:57 AM</font>
<br><font size=1 face="sans-serif">Please respond to openssl-users</font>
<br>
<td><font size=1 face="Arial"> </font>
<br><font size=1 face="sans-serif"> To: openss...@openssl.org</font>
<br><font size=1 face="sans-serif"> cc: </font>
<br><font size=1 face="sans-serif"> Subject: How to convert internal ASN1_INTEGER into little endian content octets</font></table>
<br>
<br>
<br><font size=2 face="Courier New">Hi ,<br>
<br>
i'm trying to convert ASN1_INTEGER (specifically certificate serial <br>
number) into its DER representation.<br>
I'm using i2c_ASN1_INTEGER - and if it's the right function - then I don't <br>
understand why it moves a pointer passed to it as second parameter behind <br>
reserved memory.<br>
Here is what I'm doing:<br>
<br>
int size;<br>
ASN1_INTEGER * serial;<br>
unsigned char * serialNumberDER;<br>
<br>
size = i2c_ASN1_INTEGER(serial, NULL);<br>
serialNumberDER = new unsigned char[*size];<br>
size = i2c_ASN1_INTEGER(serial, & serialNumberDER);<br>
<br>
The function has this code at the end:<br>
<br>
*pp+=ret;<br>
<br>
where pp is a pointer to serialNumberDER, so in effect it moves <br>
serialNumberDER behind created array of unsigned char.<br>
<br>
Please, explain it to me.<br>
Thanks in advance.<br>
<br>
______________________________________________________________________<br>
OpenSSL Project http://www.openssl.org<br>
User Support Mailing List openss...@openssl.org<br>
Automated List Manager majo...@openssl.org<br>
</font>
<br>
<br>
--=_alternative 004B333985256E37_=--
ASN1_INTEGER * serial;
unsigned char * serialNumberDER,*temp;
size = i2c_ASN1_INTEGER(serial, NULL);
temp=serialNumberDER = new unsigned char[*size];
size = i2c_ASN1_INTEGER(serial, &temp);
serialNumberDER contains required value
francesco petruzzi
>....
>The only real negative is remembering to put in the ampersand,
>(I guess "references" removes even this, but am I correct in
>remembering that "references" are really C++ and one should
>not count on them being in plain vanilla C? Or did references
>get added to C in the ANSI standardization process???)
--=20
Charles B (Ben) Cranston
mailto: zb...@umd.edu
http://www.wam.umd.edu/~zben
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
Andrzej,
It is common practice for ASN.1/DER libraries to increment the pointer to
the next DER element when encoding and decoding in order to support
streams of ASN.1-defined elements. For example, this technique is used to
encode and decode constructed ASN.1 types like public keys:
SubjectPublicKeyInfo ::= SEQUENCE {
algorithm AlgorithmIdentifier,
subjectPublicKey BIT STRING }
Frank
"Andrzej Posiadala" <aposi...@computerland.pl>
Sent by: owner-ope...@openssl.org
02/11/2004 11:25 AM
Please respond to openssl-users
To: Frank Balluffi/NewYork/DBNA/DeuBa@DBNA
cc: openss...@openssl.org
Subject: Re: How to convert internal ASN1_INTEGER into little endian content octets
Thanks a lot !
My VS7 cheated me :-) It doesn't display i2d_ASN1_INTEGER() in it's "Code
Insight" . But compilation is ok.
Now I'm able to use CryptEncodeObject to convert from DER encoded integer
to CRYPT_INTEGER_BLOB which is used internally in Win Crypto API. Crypto
API keeps internally multi byte integers in little-endian order and Open
SSL in big-endian, am I right ?
However, still I don't see any reason why this function increments its
second argument ? And why to the first byte after the DER-encoded INTEGER
(it's out of preallocated memory) ? If you please enlightened me I would
be grateful for.
Best regards
Andrzej
"Frank Balluffi" <frank.b...@db.com>
2004-02-11 14:41
To: aposi...@computerland.pl
cc: openss...@openssl.org
Subject: Re: How to convert internal ASN1_INTEGER into
little endian content octets
Andrzej,
length = i2d_ASN1_INTEGER(integer, 0);
der = OPENSSL_malloc(length);
if (!der)
goto error;
Frank
Subject: How to convert internal ASN1_INTEGER into little
endian content octets
Hi ,
i'm trying to convert ASN1_INTEGER (specifically certificate serial
number) into its DER representation.
I'm using i2c_ASN1_INTEGER - and if it's the right function - then I don't
understand why it moves a pointer passed to it as second parameter behind
reserved memory.
Here is what I'm doing:
int size;
ASN1_INTEGER * serial;
unsigned char * serialNumberDER;
size = i2c_ASN1_INTEGER(serial, NULL);
serialNumberDER = new unsigned char[*size];
size = i2c_ASN1_INTEGER(serial, & serialNumberDER);
The function has this code at the end:
*pp+=ret;
where pp is a pointer to serialNumberDER, so in effect it moves
serialNumberDER behind created array of unsigned char.
Please, explain it to me.
Thanks in advance.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openss...@openssl.org
Automated List Manager majo...@openssl.org
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openss...@openssl.org
Automated List Manager majo...@openssl.org
--=_alternative 005F86B885256E37_=
Content-Type: text/html; charset="us-ascii"
<br><font size=2><tt>Andrzej,</tt></font>
<br>
<br><font size=2><tt>It is common practice for ASN.1/DER libraries to increment the pointer to the next DER element when encoding and decoding in order to support streams of ASN.1-defined elements. For example, this technique is used to encode and decode constructed ASN.1 types like public keys:</tt></font>
<br>
<br><font size=2><tt> SubjectPublicKeyInfo ::= SEQUENCE {</tt></font>
<br><font size=2><tt> algorithm AlgorithmIdentifier,</tt></font>
<br><font size=2><tt> subjectPublicKey BIT STRING }</tt></font>
<br>
<br><font size=2><tt>Frank</tt></font>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td>
<td><font size=1 face="sans-serif"><b>"Andrzej Posiadala" <aposi...@computerland.pl></b></font>
<br><font size=1 face="sans-serif">Sent by: owner-ope...@openssl.org</font>
<p><font size=1 face="sans-serif">02/11/2004 11:25 AM</font>
<br><font size=1 face="sans-serif">Please respond to openssl-users</font>
<br>
<td><font size=1 face="Arial"> </font>
<br><font size=1 face="sans-serif"> To: Frank Balluffi/NewYork/DBNA/DeuBa@DBNA</font>
<br><font size=1 face="sans-serif"> cc: openss...@openssl.org</font>
<br><font size=1 face="sans-serif"> Subject: Re: How to convert internal ASN1_INTEGER into little endian content octets</font></table>
<br>
<br>
<br><font size=2 face="Courier New">Thanks a lot !<br>
My VS7 cheated me :-) It doesn't display i2d_ASN1_INTEGER() in it's "Code <br>
Insight" . But compilation is ok.<br>
Now I'm able to use CryptEncodeObject to convert from DER encoded integer <br>
to CRYPT_INTEGER_BLOB which is used internally in Win Crypto API. Crypto <br>
API keeps internally multi byte integers in little-endian order and Open <br>
SSL in big-endian, am I right ?<br>
<br>
However, still I don't see any reason why this function increments its <br>
second argument ? And why to the first byte after the DER-encoded INTEGER <br>
(it's out of preallocated memory) ? If you please enlightened me I would <br>
be grateful for.<br>
<br>
Best regards<br>
Andrzej<br>
<br>
<br>
<br>
<br>
<br>
"Frank Balluffi" <frank.b...@db.com><br>
2004-02-11 14:41<br>
<br>
<br>
To: aposi...@computerland.pl<br>
cc: openss...@openssl.org<br>
Subject: Re: How to convert internal ASN1_INTEGER into little endian content octets<br>
<br>
<br>
<br>
Andrzej, <br>
<br>
Call i2d_ASN1_INTEGER to DER-encode an ASN.1 INTEGER. Pass 0 or NULL as <br>
the second argument to i2d_ASN1_INTEGER to determine the length of the <br>
DER-encoded INTEGER. If you pass a non-zero value as the second argument <br>
to i2d_ASN1_INTEGER, the function will DER-encode the INTEGER and <br>
increment the second argument to the first byte after the DER-encoded <br>
INTEGER. Looks like (I did not compile this code): <br>
<br>
ASN1_INTEGER * integer; /* points to an ASN1_INTEGER */ <br>
unsigned char * der = NULL; <br>
unsigned char * derNext = NULL; <br>
int length = 0; <br>
<br>
length = i2d_ASN1_INTEGER(integer, 0); <br>
<br>
if (length <= 0) <br>
goto error; <br>
<br>
der = OPENSSL_malloc(length); <br>
<br>
if (!der) <br>
goto error; <br>
<br>
/* <br>
Because i2d functions modify their second argument, use the variable <br>
derNext. <br>
*/ <br>
<br>
derNext = der; <br>
length = i2d_ASN1_INTEGER(integer, &derNext); <br>
<br>
if (length <= 0) <br>
goto error; <br>
<br>
Frank <br>
<br>
<br>
<br>
<br>
"Andrzej Posiadala" <aposi...@computerland.pl> <br>
Sent by: owner-ope...@openssl.org </font>
<br><font size=2 face="Courier New">02/11/2004 07:57 AM <br>
Please respond to openssl-users <br>
<br>
To: openss...@openssl.org <br>
cc: <br>
Subject: How to convert internal ASN1_INTEGER into little <br>
endian content octets<br>
<br>
<br>
<br>
Hi ,<br>
<br>
i'm trying to convert ASN1_INTEGER (specifically certificate serial <br>
number) into its DER representation.<br>
I'm using i2c_ASN1_INTEGER - and if it's the right function - then I don't <br>
<br>
<br>
<br>
<br>
______________________________________________________________________<br>
OpenSSL Project http://www.openssl.org<br>
User Support Mailing List openss...@openssl.org<br>
Automated List Manager majo...@openssl.org<br>
</font>
<br>
<br>
--=_alternative 005F86B885256E37_=--