progs/perftest.c: Use from Glibc syscall numbers.
[catacomb] / math / ec-raw.c
index acee1b6..497e191 100644 (file)
@@ -54,6 +54,9 @@
  *             @EC_EXPLY@ is set, then an explicit %$y$%-coordinate is
  *             output in full.  Otherwise the %$y$%-coordinate is
  *             suppressed.
+ *
+ *             Returns failure (@-1@) if the flags are invalid, or if there
+ *             isn't enough space in the output buffer.
  */
 
 int ec_ec2osp(ec_curve *c, unsigned f, buf *b, const ec *p)
@@ -62,15 +65,22 @@ int ec_ec2osp(ec_curve *c, unsigned f, buf *b, const ec *p)
   size_t n;
   ec t = EC_INIT;
 
+  /* --- Check the requested flags for sanity --- */
+
+  if (!f) f = EC_XONLY;
+  if (f & ~((f & EC_XONLY) ? EC_XONLY :
+           (f & EC_CMPR) ? (EC_CMPR | EC_EXPLY | EC_SORT) :
+           (f & EC_EXPLY) ? EC_EXPLY :
+           0u))
+    return (-1);
+
   /* --- Point at infinity --- */
 
   if (EC_ATINF(p)) return (buf_putbyte(b, 0));
 
   /* --- Fix up the format byte, compressing the %$y$%-coordinate --- */
 
-  if (!f)
-    f = EC_XONLY;
-  else if (f & EC_CMPR) {
+  if (f & EC_CMPR) {
     if (!(f & EC_SORT))
       f |= EC_COMPR(c, p) ? EC_YBIT : 0;
     else {