- PUT_32BIT(blob, 19);
- sprintf((char*)blob+4, "ecdsa-sha2-nistp%d", curve->fieldBits);
- PUT_32BIT(blob+4+19, 8);
- sprintf((char*)blob+4+19+4, "nistp%d", curve->fieldBits);
- PUT_32BIT(blob+4+19+4+8, len);
- memcpy(blob+4+19+4+8+4, p, len);
- PUT_32BIT(blob+4+19+4+8+4+len, privlen);
- memcpy(blob+4+19+4+8+4+len+4, priv, privlen);
- retkey->data = retkey->alg->createkey(blob, 4+19+4+8+4+len,
- blob+4+19+4+8+4+len,
- 4+privlen);
+
+ q = blob;
+
+ algnamelen = strlen(alg->name);
+ PUT_32BIT(q, algnamelen); q += 4;
+ memcpy(q, alg->name, algnamelen); q += algnamelen;
+
+ curvenamelen = strlen(curve->name);
+ PUT_32BIT(q, curvenamelen); q += 4;
+ memcpy(q, curve->name, curvenamelen); q += curvenamelen;
+
+ PUT_32BIT(q, len); q += 4;
+ memcpy(q, p, len); q += len;
+
+ /*
+ * To be acceptable to our createkey(), the private blob must
+ * contain a valid mpint, i.e. without the top bit set. But
+ * the input private string may have the top bit set, so we
+ * prefix a zero byte to ensure createkey() doesn't fail for
+ * that reason.
+ */
+ PUT_32BIT(q, privlen+1);
+ q[4] = 0;
+ memcpy(q+5, priv, privlen);
+
+ retkey->data = retkey->alg->createkey(retkey->alg,
+ blob, q-blob,
+ q, 5+privlen);
+