- buf = malloc(100);
- if (!buf)
- return buf;
- snprintf(buf, 100, "%ld", (long)*val);
- return buf;
+ buf = BN_bn2dec(num);
+ if (buf == NULL)
+ return; /* XXX do anything here? */
+ fprintf(fp, "%s", buf);
+ free(buf);
+}
+
+#else
+
+static void
+BN_print_fp(FILE *fp, const BIGNUM *num)
+{
+ fprintf(fp, "%lx", (unsigned long)*num);
+}
+
+static void
+BN_print_dec_fp(FILE *fp, const BIGNUM *num)
+{
+ fprintf(fp, "%lu", (unsigned long)*num);
+}
+
+static int
+BN_dec2bn(BIGNUM **a, const char *str)
+{
+ char *p;
+
+ errno = 0;
+ **a = strtoul(str, &p, 10);
+ return (errno == 0 ? 1 : 0); /* OpenSSL returns 0 on error! */
+}
+
+static int
+BN_hex2bn(BIGNUM **a, const char *str)
+{
+ char *p;
+
+ errno = 0;
+ **a = strtoul(str, &p, 16);
+ return (errno == 0 ? 1 : 0); /* OpenSSL returns 0 on error! */