Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nettle
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Wim Lewis
nettle
Commits
c049b56d
Commit
c049b56d
authored
12 years ago
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
New functions in gmp-glue.c.
parent
9d5b269d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ChangeLog
+6
-0
6 additions, 0 deletions
ChangeLog
gmp-glue.c
+60
-0
60 additions, 0 deletions
gmp-glue.c
gmp-glue.h
+22
-0
22 additions, 0 deletions
gmp-glue.h
with
88 additions
and
0 deletions
ChangeLog
+
6
−
0
View file @
c049b56d
2013-02-18 Niels Möller <nisse@lysator.liu.se>
2013-02-18 Niels Möller <nisse@lysator.liu.se>
* gmp-glue.c (_mpz_set_mpn): New convenience function.
(_mpn_set_base256): New function.
(_gmp_alloc_limbs): New function.
(_gmp_free_limbs): New function.
* gmp-glue.h: Corresponding declarations. Include nettle-stdinh.h.
* examples/Makefile.in (HOGWEED_TARGETS): Renamed, was
* examples/Makefile.in (HOGWEED_TARGETS): Renamed, was
RSA_TARGETS. Added ecc-benchmark$(EXEEXT).
RSA_TARGETS. Added ecc-benchmark$(EXEEXT).
(SOURCES): Added ecc-benchmark.c.
(SOURCES): Added ecc-benchmark.c.
...
...
This diff is collapsed.
Click to expand it.
gmp-glue.c
+
60
−
0
View file @
c049b56d
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#endif
#endif
#include
<assert.h>
#include
<assert.h>
#include
<stdlib.h>
#include
"gmp-glue.h"
#include
"gmp-glue.h"
...
@@ -135,6 +136,13 @@ _mpz_done_limbs (mpz_ptr x, mp_size_t n)
...
@@ -135,6 +136,13 @@ _mpz_done_limbs (mpz_ptr x, mp_size_t n)
SIZ
(
x
)
=
n
;
SIZ
(
x
)
=
n
;
}
}
void
_mpz_set_mpn
(
mpz_t
r
,
const
mp_limb_t
*
xp
,
mp_size_t
xn
)
{
mpn_copyi
(
_mpz_write_limbs
(
r
,
xn
),
xp
,
xn
);
_mpz_done_limbs
(
r
,
xn
);
}
/* Needs some ugly casts. */
/* Needs some ugly casts. */
mpz_srcptr
mpz_srcptr
_mpz_init_mpn
(
mpz_ptr
x
,
const
mp_limb_t
*
xp
,
mp_size_t
xs
)
_mpz_init_mpn
(
mpz_ptr
x
,
const
mp_limb_t
*
xp
,
mp_size_t
xs
)
...
@@ -148,3 +156,55 @@ _mpz_init_mpn (mpz_ptr x, const mp_limb_t *xp, mp_size_t xs)
...
@@ -148,3 +156,55 @@ _mpz_init_mpn (mpz_ptr x, const mp_limb_t *xp, mp_size_t xs)
x
->
_mp_d
=
(
mp_limb_t
*
)
xp
;
x
->
_mp_d
=
(
mp_limb_t
*
)
xp
;
return
x
;
return
x
;
}
}
void
_mpn_set_base256
(
mp_limb_t
*
rp
,
mp_size_t
rn
,
const
uint8_t
*
xp
,
size_t
xn
)
{
size_t
xi
;
mp_limb_t
out
;
unsigned
bits
;
for
(
xi
=
xn
,
out
=
bits
=
0
;
xi
>
0
&&
rn
>
0
;
)
{
mp_limb_t
in
=
xp
[
--
xi
];
out
|=
(
in
<<
bits
)
&
GMP_NUMB_MASK
;
bits
+=
8
;
if
(
bits
>=
GMP_NUMB_BITS
)
{
*
rp
++
=
out
;
rn
--
;
bits
-=
GMP_NUMB_BITS
;
out
=
in
>>
(
8
-
bits
);
}
}
if
(
rn
>
0
)
{
*
rp
++
=
out
;
if
(
--
rn
>
0
)
mpn_zero
(
rp
,
rn
);
}
}
mp_limb_t
*
_gmp_alloc_limbs
(
mp_size_t
n
)
{
void
*
(
*
alloc_func
)(
size_t
);
assert
(
n
>
0
);
mp_get_memory_functions
(
&
alloc_func
,
NULL
,
NULL
);
return
(
mp_limb_t
*
)
alloc_func
(
(
size_t
)
n
*
sizeof
(
mp_limb_t
));
}
void
_gmp_free_limbs
(
mp_limb_t
*
p
,
mp_size_t
n
)
{
void
(
*
free_func
)(
void
*
,
size_t
);
assert
(
n
>
0
);
assert
(
p
!=
0
);
mp_get_memory_functions
(
NULL
,
NULL
,
&
free_func
);
free_func
(
p
,
(
size_t
)
n
*
sizeof
(
mp_limb_t
));
}
This diff is collapsed.
Click to expand it.
gmp-glue.h
+
22
−
0
View file @
c049b56d
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
#include
<gmp.h>
#include
<gmp.h>
#include
"nettle-stdint.h"
/* Name mangling. */
/* Name mangling. */
#define _mpz_cmp_limbs _nettle_mpz_cmp_limbs
#define _mpz_cmp_limbs _nettle_mpz_cmp_limbs
#define _mpz_read_limbs _nettle_mpz_read_limbs
#define _mpz_read_limbs _nettle_mpz_read_limbs
...
@@ -33,7 +35,11 @@
...
@@ -33,7 +35,11 @@
#define _mpz_write_limbs _nettle_mpz_write_limbs
#define _mpz_write_limbs _nettle_mpz_write_limbs
#define _mpz_modify_limbs _nettle_mpz_modify_limbs
#define _mpz_modify_limbs _nettle_mpz_modify_limbs
#define _mpz_done_limbs _nettle_mpz_done_limbs
#define _mpz_done_limbs _nettle_mpz_done_limbs
#define _mpz_set_mpn _nettle_mpz_set_mpn
#define _mpz_init_mpn _nettle_mpz_init_mpn
#define _mpz_init_mpn _nettle_mpz_init_mpn
#define _mpn_set_base256 _nettle_mpn_set_base256
#define _gmp_alloc_limbs _nettle_gmp_alloc_limbs
#define _gmp_free_limbs _nettle_gmp_free_limbs
/* Some functions for interfacing between mpz and mpn code. Signs of
/* Some functions for interfacing between mpz and mpn code. Signs of
the mpz numbers are generally ignored. */
the mpz numbers are generally ignored. */
...
@@ -76,10 +82,26 @@ _mpz_modify_limbs (mpz_ptr x, mp_size_t n);
...
@@ -76,10 +82,26 @@ _mpz_modify_limbs (mpz_ptr x, mp_size_t n);
void
void
_mpz_done_limbs
(
mpz_ptr
x
,
mp_size_t
n
);
_mpz_done_limbs
(
mpz_ptr
x
,
mp_size_t
n
);
void
_mpz_set_mpn
(
mpz_t
r
,
const
mp_limb_t
*
xp
,
mp_size_t
xn
);
/* Using an mpn number as an mpz. Can be used for read-only access
/* Using an mpn number as an mpz. Can be used for read-only access
only. x must not be cleared or reallocated. */
only. x must not be cleared or reallocated. */
mpz_srcptr
mpz_srcptr
_mpz_init_mpn
(
mpz_ptr
x
,
const
mp_limb_t
*
xp
,
mp_size_t
xs
);
_mpz_init_mpn
(
mpz_ptr
x
,
const
mp_limb_t
*
xp
,
mp_size_t
xs
);
/* Like mpn_set_str, but always writes rn limbs. If input is larger,
higher bits are ignored. */
void
_mpn_set_base256
(
mp_limb_t
*
rp
,
mp_size_t
rn
,
const
uint8_t
*
xp
,
size_t
xn
);
mp_limb_t
*
_gmp_alloc_limbs
(
mp_size_t
n
);
void
_gmp_free_limbs
(
mp_limb_t
*
p
,
mp_size_t
n
);
#endif
/* NETTLE_GMP_GLUE_H_INCLUDED */
#endif
/* NETTLE_GMP_GLUE_H_INCLUDED */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment