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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dmitry Baryshkov
nettle
Commits
ce5c66d7
Commit
ce5c66d7
authored
Jan 20, 2015
by
Niels Möller
Browse files
Options
Downloads
Patches
Plain Diff
Implemented handling of NETTLE_FAT_OVERRIDE.
parent
68aa75e3
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
+8
-0
8 additions, 0 deletions
ChangeLog
fat-setup.h
+5
-0
5 additions, 0 deletions
fat-setup.h
fat-x86_64.c
+72
-14
72 additions, 14 deletions
fat-x86_64.c
with
85 additions
and
14 deletions
ChangeLog
+
8
−
0
View file @
ce5c66d7
2015-01-20 Niels Möller <nisse@lysator.liu.se>
2015-01-20 Niels Möller <nisse@lysator.liu.se>
* fat-x86_64.c (get_x86_features): New function. Check
NETTLE_FAT_OVERRIDE environment variable.
(fat_init): Use it.
* fat-setup.h (secure_getenv) [!HAVE_SECURE_GETENV]: Dummy
definition, returning NULL.
(ENV_OVERRIDE): New constant.
* configure.ac: Check for secure_getenv function.
* configure.ac: Check for secure_getenv function.
2015-01-19 Niels Möller <nisse@lysator.liu.se>
2015-01-19 Niels Möller <nisse@lysator.liu.se>
...
...
This diff is collapsed.
Click to expand it.
fat-setup.h
+
5
−
0
View file @
ce5c66d7
...
@@ -70,7 +70,12 @@
...
@@ -70,7 +70,12 @@
# endif
# endif
#endif
#endif
#if !HAVE_SECURE_GETENV
#define secure_getenv(s) NULL
#endif
#define ENV_VERBOSE "NETTLE_FAT_VERBOSE"
#define ENV_VERBOSE "NETTLE_FAT_VERBOSE"
#define ENV_OVERRIDE "NETTLE_FAT_OVERRIDE"
/* DECLARE_FAT_FUNC(name, ftype)
/* DECLARE_FAT_FUNC(name, ftype)
*
*
...
...
This diff is collapsed.
Click to expand it.
fat-x86_64.c
+
72
−
14
View file @
ce5c66d7
...
@@ -29,6 +29,8 @@
...
@@ -29,6 +29,8 @@
not, see http://www.gnu.org/licenses/.
not, see http://www.gnu.org/licenses/.
*/
*/
#define _GNU_SOURCE
#if HAVE_CONFIG_H
#if HAVE_CONFIG_H
# include "config.h"
# include "config.h"
#endif
#endif
...
@@ -46,6 +48,61 @@
...
@@ -46,6 +48,61 @@
void
_nettle_cpuid
(
uint32_t
input
,
uint32_t
regs
[
4
]);
void
_nettle_cpuid
(
uint32_t
input
,
uint32_t
regs
[
4
]);
struct
x86_features
{
enum
x86_vendor
{
X86_OTHER
,
X86_INTEL
,
X86_AMD
}
vendor
;
int
have_aesni
;
};
#define SKIP(s, slen, literal, llen) \
(((slen) >= (llen) && memcmp ((s), (literal), llen) == 0) \
? ((slen) -= (llen), (s) += (llen), 1) : 0)
#define MATCH(s, slen, literal, llen) \
((slen) == (llen) && memcmp ((s), (literal), llen) == 0)
static
void
get_x86_features
(
struct
x86_features
*
features
)
{
const
char
*
s
;
features
->
vendor
=
X86_OTHER
;
features
->
have_aesni
=
0
;
s
=
secure_getenv
(
ENV_OVERRIDE
);
if
(
s
)
for
(;;)
{
const
char
*
sep
=
strchr
(
s
,
','
);
size_t
length
=
sep
?
(
size_t
)
(
sep
-
s
)
:
strlen
(
s
);
if
(
SKIP
(
s
,
length
,
"vendor:"
,
7
))
{
if
(
MATCH
(
s
,
length
,
"intel"
,
5
))
features
->
vendor
=
X86_INTEL
;
else
if
(
MATCH
(
s
,
length
,
"amd"
,
3
))
features
->
vendor
=
X86_AMD
;
}
else
if
(
MATCH
(
s
,
length
,
"aesni"
,
5
))
features
->
have_aesni
=
1
;
if
(
!
sep
)
break
;
s
=
sep
+
1
;
}
else
{
uint32_t
cpuid_data
[
4
];
_nettle_cpuid
(
0
,
cpuid_data
);
if
(
memcmp
(
cpuid_data
+
1
,
"Genu"
"ntel"
"ineI"
,
12
)
==
0
)
features
->
vendor
=
X86_INTEL
;
else
if
(
memcmp
(
cpuid_data
+
1
,
"Auth"
"cAMD"
"enti"
,
12
)
==
0
)
features
->
vendor
=
X86_AMD
;
_nettle_cpuid
(
1
,
cpuid_data
);
if
(
cpuid_data
[
2
]
&
0x02000000
)
features
->
have_aesni
=
1
;
}
}
DECLARE_FAT_FUNC
(
_nettle_aes_encrypt
,
aes_crypt_internal_func
)
DECLARE_FAT_FUNC
(
_nettle_aes_encrypt
,
aes_crypt_internal_func
)
DECLARE_FAT_FUNC_VAR
(
aes_encrypt
,
aes_crypt_internal_func
,
x86_64
)
DECLARE_FAT_FUNC_VAR
(
aes_encrypt
,
aes_crypt_internal_func
,
x86_64
)
DECLARE_FAT_FUNC_VAR
(
aes_encrypt
,
aes_crypt_internal_func
,
aesni
)
DECLARE_FAT_FUNC_VAR
(
aes_encrypt
,
aes_crypt_internal_func
,
aesni
)
...
@@ -66,7 +123,7 @@ static void CONSTRUCTOR
...
@@ -66,7 +123,7 @@ static void CONSTRUCTOR
fat_init
(
void
)
fat_init
(
void
)
{
{
static
volatile
int
initialized
=
0
;
static
volatile
int
initialized
=
0
;
uint32_t
cpuid_data
[
4
]
;
struct
x86_features
features
;
int
verbose
;
int
verbose
;
if
(
initialized
)
if
(
initialized
)
return
;
return
;
...
@@ -76,39 +133,40 @@ fat_init (void)
...
@@ -76,39 +133,40 @@ fat_init (void)
if
(
verbose
)
if
(
verbose
)
fprintf
(
stderr
,
"libnettle: fat library initialization.
\n
"
);
fprintf
(
stderr
,
"libnettle: fat library initialization.
\n
"
);
_nettle_cpuid
(
1
,
cpuid_data
);
get_x86_features
(
&
features
);
if
(
verbose
)
if
(
verbose
)
fprintf
(
stderr
,
"libnettle: cpuid 1: %08x, %08x, %08x, %08x
\n
"
,
{
cpuid_data
[
0
],
cpuid_data
[
1
],
cpuid_data
[
2
],
cpuid_data
[
3
]);
const
char
*
const
vendor_names
[
3
]
=
{
"other"
,
"intel"
,
"amd"
};
if
(
cpuid_data
[
2
]
&
0x02000000
)
fprintf
(
stderr
,
"libnettle: cpu features: vendor:%s%s
\n
"
,
vendor_names
[
features
.
vendor
],
features
.
have_aesni
?
",aesni"
:
""
);
}
if
(
features
.
have_aesni
)
{
{
if
(
verbose
)
if
(
verbose
)
fprintf
(
stderr
,
"libnettle: aes instructions
available
.
\n
"
);
fprintf
(
stderr
,
"libnettle:
using
aes instructions.
\n
"
);
_nettle_aes_encrypt_vec
=
_nettle_aes_encrypt_aesni
;
_nettle_aes_encrypt_vec
=
_nettle_aes_encrypt_aesni
;
_nettle_aes_decrypt_vec
=
_nettle_aes_decrypt_aesni
;
_nettle_aes_decrypt_vec
=
_nettle_aes_decrypt_aesni
;
}
}
else
else
{
{
if
(
verbose
)
if
(
verbose
)
fprintf
(
stderr
,
"libnettle: aes instructions
not available
.
\n
"
);
fprintf
(
stderr
,
"libnettle:
not using
aes instructions.
\n
"
);
_nettle_aes_encrypt_vec
=
_nettle_aes_encrypt_x86_64
;
_nettle_aes_encrypt_vec
=
_nettle_aes_encrypt_x86_64
;
_nettle_aes_decrypt_vec
=
_nettle_aes_decrypt_x86_64
;
_nettle_aes_decrypt_vec
=
_nettle_aes_decrypt_x86_64
;
}
}
_nettle_cpuid
(
0
,
cpuid_data
);
if
(
features
.
vendor
==
X86_INTEL
)
if
(
memcmp
(
&
cpuid_data
[
1
],
"Genu"
,
4
)
==
0
&&
memcmp
(
&
cpuid_data
[
3
],
"ineI"
,
4
)
==
0
&&
memcmp
(
&
cpuid_data
[
2
],
"ntel"
,
4
)
==
0
)
{
{
if
(
verbose
)
if
(
verbose
)
fprintf
(
stderr
,
"libnettle: intel SSE2 will be used for
XOR
.
\n
"
);
fprintf
(
stderr
,
"libnettle: intel SSE2 will be used for
memxor
.
\n
"
);
nettle_memxor_vec
=
_nettle_memxor_sse2
;
nettle_memxor_vec
=
_nettle_memxor_sse2
;
}
}
else
else
{
{
if
(
verbose
)
if
(
verbose
)
fprintf
(
stderr
,
"libnettle: intel SSE2 will not be used for
XOR
.
\n
"
);
fprintf
(
stderr
,
"libnettle: intel SSE2 will not be used for
memxor
.
\n
"
);
nettle_memxor_vec
=
_nettle_memxor_x86_64
;
nettle_memxor_vec
=
_nettle_memxor_x86_64
;
}
}
...
...
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