summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--doc/gcrypt.texi11
-rw-r--r--src/gcrypt.h.in10
-rw-r--r--src/libgcrypt.def2
-rw-r--r--src/libgcrypt.vers2
-rw-r--r--src/visibility.c14
-rw-r--r--src/visibility.h4
7 files changed, 47 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index c4f89c17..5dea5520 100644
--- a/NEWS
+++ b/NEWS
@@ -60,6 +60,11 @@ Noteworthy changes in version 1.6.0 (unreleased)
gcry_mpi_ec_mul NEW.
GCRYMPI_FLAG_IMMUTABLE NEW.
GCRYMPI_FLAG_CONST NEW.
+ GCRYMPI_CONST_ONE NEW.
+ GCRYMPI_CONST_TWO NEW.
+ GCRYMPI_CONST_THREE NEW.
+ GCRYMPI_CONST_FOUR NEW.
+ GCRYMPI_CONST_EIGHT NEW.
GCRYPT_VERSION_NUMBER NEW.
GCRY_KDF_SCRYPT NEW.
gcry_pubkey_get_sexp NEW.
diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi
index cace087b..d4c41940 100644
--- a/doc/gcrypt.texi
+++ b/doc/gcrypt.texi
@@ -4054,6 +4054,11 @@ coordinate is not required, @code{NULL} may be passed to @var{x} or
@var{y}. @var{ctx} is the context object which has been created using
@code{gcry_mpi_ec_new}. Returns 0 on success or not 0 if @var{point}
is at infinity.
+
+Note that you can use @code{gcry_mpi_ec_set_point} with the value
+@code{GCRYMPI_CONST_ONE} for @var{z} to convert affine coordinates
+back into projective coordinates.
+
@end deftypefun
@deftypefun void gcry_mpi_ec_dup ( @
@@ -4127,7 +4132,11 @@ If this flag is set, the MPI is marked as a constant and as immutable
Setting or changing the value of that MPI is ignored and an error
message is logged. Such an MPI will never be deallocated and may thus
be used without copying. Note that using gcry_mpi_copy will return a
-copy of that constant with this and the immutable flag cleared.
+copy of that constant with this and the immutable flag cleared. A few
+commonly used constants are pre-defined and accessible using the
+macros @code{GCRYMPI_CONST_ONE}, @code{GCRYMPI_CONST_TWO},
+@code{GCRYMPI_CONST_THREE}, @code{GCRYMPI_CONST_FOUR}, and
+@code{GCRYMPI_CONST_EIGHT}.
@end table
@deftypefun void gcry_mpi_set_flag (@w{gcry_mpi_t @var{a}}, @
diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in
index 85213ea4..f472b02b 100644
--- a/src/gcrypt.h.in
+++ b/src/gcrypt.h.in
@@ -467,6 +467,13 @@ enum gcry_mpi_flag
};
+/* Macros to return pre-defined MPI constants. */
+#define GCRYMPI_CONST_ONE (_gcry_mpi_get_const (1))
+#define GCRYMPI_CONST_TWO (_gcry_mpi_get_const (2))
+#define GCRYMPI_CONST_THREE (_gcry_mpi_get_const (3))
+#define GCRYMPI_CONST_FOUR (_gcry_mpi_get_const (4))
+#define GCRYMPI_CONST_EIGHT (_gcry_mpi_get_const (8))
+
/* Allocate a new big integer object, initialize it with 0 and
initially allocate memory for a number of at least NBITS. */
gcry_mpi_t gcry_mpi_new (unsigned int nbits);
@@ -692,6 +699,9 @@ void gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
/* Return true when the FLAG is set for A. */
int gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
+/* Private function - do not use. */
+gcry_mpi_t _gcry_mpi_get_const (int no);
+
/* Unless the GCRYPT_NO_MPI_MACROS is used, provide a couple of
convenience macros for the big integer functions. */
#ifndef GCRYPT_NO_MPI_MACROS
diff --git a/src/libgcrypt.def b/src/libgcrypt.def
index 4da46232..9eaf8a7a 100644
--- a/src/libgcrypt.def
+++ b/src/libgcrypt.def
@@ -234,3 +234,5 @@ EXPORTS
gcry_mpi_ec_mul @211
gcry_pubkey_get_sexp @212
+
+ _gcry_mpi_get_const @213
diff --git a/src/libgcrypt.vers b/src/libgcrypt.vers
index 29e46dbe..6aaf0f13 100644
--- a/src/libgcrypt.vers
+++ b/src/libgcrypt.vers
@@ -98,6 +98,8 @@ GCRYPT_1.6 {
gcry_mpi_ec_get_affine;
gcry_mpi_ec_dup; gcry_mpi_ec_add; gcry_mpi_ec_mul;
+ _gcry_mpi_get_const;
+
gcry_ctx_release;
local:
diff --git a/src/visibility.c b/src/visibility.c
index b503be66..c86d31b2 100644
--- a/src/visibility.c
+++ b/src/visibility.c
@@ -601,6 +601,20 @@ gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
return _gcry_mpi_get_flag (a, flag);
}
+gcry_mpi_t
+_gcry_mpi_get_const (int no)
+{
+ switch (no)
+ {
+ case 1: return _gcry_mpi_const (MPI_C_ONE);
+ case 2: return _gcry_mpi_const (MPI_C_TWO);
+ case 3: return _gcry_mpi_const (MPI_C_THREE);
+ case 4: return _gcry_mpi_const (MPI_C_FOUR);
+ case 8: return _gcry_mpi_const (MPI_C_EIGHT);
+ default: log_bug("unsupported GCRYMPI_CONST_ macro used\n");
+ }
+}
+
gcry_error_t
gcry_cipher_open (gcry_cipher_hd_t *handle,
int algo, int mode, unsigned int flags)
diff --git a/src/visibility.h b/src/visibility.h
index 1564e865..6887f37b 100644
--- a/src/visibility.h
+++ b/src/visibility.h
@@ -594,6 +594,10 @@ MARK_VISIBLE (gcry_mpi_test_bit)
MARK_VISIBLE (gcry_ctx_release)
+/* Functions used to implement macros. */
+MARK_VISIBLEX(_gcry_mpi_get_const)
+
+
#undef MARK_VISIBLE
#endif /*_GCRY_INCLUDED_BY_VISIBILITY_C*/