string(46..122)
crypt(string(1..255)
password
)
bool
crypt(string(1..255)
input_password
, string(46..122)
crypted_password
)
string(46..122)
crypt()
This function crypts and verifies a short string (only the first 8 characters are significant).
The first syntax crypts the string password
into something that
is hopefully hard to decrypt.
The second syntax is used to verify typed_password
against
crypted_password
, and returns 1
if they match, and
0
(zero) otherwise.
The third syntax generates a random string and then crypts it, creating a string useful as a password.
Note that strings containing null characters will only be processed up until the null character.
Password handling.
This module handles generation and verification of password hashes.
verify()
, hash()
, crypt()
string(7bit)
hash(string(8bit)
password
, string(7bit)
|void
scheme
, int(0..)
|void
rounds
)
Generate a hash of password
suitable for verify()
.
password
Password to hash.
scheme
Password hashing scheme. If not specified the strongest available will be used.
If an unsupported scheme is specified an error will be thrown.
Supported schemes are:
Crypt(3C)-style:
| Use the strongest crypt(3C)-style hash that is supported. |
| |
| |
|
|
| |
|
|
| |
| The NTLM MD4 hash. |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
|
|
| |
| |
| |
| Same as |
| Same as |
| |
| Same as |
| |
|
|
| |
|
|
| |
|
|
| |
|
|
LDAP (RFC 2307)-style. Don't use these if you can avoid it, since they are suspectible to attacks. In particular avoid the unsalted variants at all costs:
|
|
| |
|
|
| |
|
|
| |
|
|
|
rounds
The number of rounds to use in parameterized schemes. If not specified the scheme specific default will be used.
Returns a string suitable for verify()
. This means that
the hashes will be prepended with the suitable markers.
Note that the availability of SHA512
depends on the version
of Nettle
that Pike has been compiled with.
This function was added in Pike 7.8.755.
verify()
, predef::crypt()
, Nettle.crypt_md5()
,
Nettle.Hash()->crypt_hash()
int
verify(string(8bit)
password
, string(7bit)
hash
)
Verify a password against a hash.
This function attempts to support most common password hashing schemes.
password
Binary password. This is typically is typically a textual
string normalized according to
string_to_utf8(Unicode.normalize(raw_password, "NFC"))
,
but some operating systems (eg MacOS X) may have other
conventions.
hash
The hash
can be on any of the following formats.
LDAP-style (RFC 2307) hashes:
| The |
| The |
| The |
| The |
| The |
Crypt-style hashes:
| The string is interpreted according to the
"Unix crypt using SHA-256 and SHA-512" standard
Version 0.4 2008-4-3, where |
| This is the same algorithm as the one above, but with the
number of rounds specified by |
| The string is interpreted according to the
"Unix crypt using SHA-256 and SHA-512" standard
Version 0.4 2008-4-3, where |
| This is the same algorithm as the one above, but with the
number of rounds specified by |
| This is interpreted as the NT LANMANAGER (NTLM) password hash. It is a hex representation of MD4 of the password. |
| The string is interpreted according to the GNU libc2 extension
of |
| The string is interpreted as a NetBSD-style |
| The string is interpreted as a PHPass' Portable Hash password hash,
where |
| Same as |
| This is handled as a Drupal upgraded PHPass Portable Hash password.
The password is run once through |
| The string is interpreted as a PHPass' Portable Hash password hash,
where the base hashing alorithm has been switched to |
| The string is interpreted as a PHPass' Portable Hash password hash,
where the base hashing alorithm has been switched to |
| The string is interpreted as |
| The string is interpreted as |
| The string is interpreted as |
| The string is interpreted as the Django variant of
|
| The |
| The empty password hash matches all passwords. |
Returns 1
on success, and 0
(zero) otherwise.
This function was added in Pike 7.8.755.
hash()
, predef::crypt()
This is pike glue for GSS-API ver 2 as specified in RFC 2743.
GSS-API is used to authenticate users and servers, and optionally also to encrypt communication between them. The API is generic and can be used without any knowledge of the actual implementation of these security services, which is typically provided by the operating system.
The most common implementation at the time of writing is Kerberos, which means that the main benefit of this API is to allow clients and servers to authenticate each other using Kerberos, thereby making single sign-on possible in a Kerberized environment.
All functions in this module that wrap GSS-API routines may throw
GSSAPI.Error
, and by default they do so for all such errors. Only in
some special cases do they return when a GSS-API error has happened,
and this is then noted in the documentation.
constant
int
GSSAPI.INITIATE
constant
int
GSSAPI.ACCEPT
constant
int
GSSAPI.BOTH
Flags for indicating how a GSSAPI.Cred
object may be used:
The credential can only be used to initiate security contexts
(i.e. using GSSAPI.InitContext
).
The credential can only be used to accept security contexts
(i.e. using GSSAPI.AcceptContext
).
The credential may be used both to initiate or accept security contexts.
constant
int
GSSAPI.DELEG_FLAG
constant
int
GSSAPI.MUTUAL_FLAG
constant
int
GSSAPI.REPLAY_FLAG
constant
int
GSSAPI.SEQUENCE_FLAG
constant
int
GSSAPI.CONF_FLAG
constant
int
GSSAPI.INTEG_FLAG
constant
int
GSSAPI.ANON_FLAG
constant
int
GSSAPI.PROT_READY_FLAG
constant
int
GSSAPI.TRANS_FLAG
Bitfield flags returned by e.g. GSSAPI.Context.services
to
denote various services that are available in the context.
Brief descriptions of the flags:
Delegation. See RFC 2743 section 1.2.9.
Mutual authentication (actually, acceptor authentication). See RFC 2743 section 1.1.1.3 and RFC 2743 section 1.2.5.
Per-message replay detection. See RFC 2743 section 1.2.3.
Per-message sequencing. See RFC 2743 section 1.2.3.
Per-message confidentiality. See RFC 2743 section 1.2.2.
Per-message integrity. See RFC 2743 section 1.2.2.
Anonymous authentication. See RFC 2743 section 1.2.5.
Might be set before the context establishment has finished, to
denote that per-message protection already is available. See
RFC 2743 section 1.2.7. Is always set in GSSAPI.Context
and
derived classes when the context is established.
The context can be transferred between processes using
GSSAPI.Context.export
. See RFC 2743 section 1.2.10.
constant
int
GSSAPI.BAD_MECH
constant
int
GSSAPI.BAD_NAME
constant
int
GSSAPI.BAD_NAMETYPE
constant
int
GSSAPI.BAD_BINDINGS
constant
int
GSSAPI.BAD_STATUS
constant
int
GSSAPI.BAD_SIG
constant
int
GSSAPI.NO_CRED
constant
int
GSSAPI.NO_CONTEXT
constant
int
GSSAPI.DEFECTIVE_TOKEN
constant
int
GSSAPI.DEFECTIVE_CREDENTIAL
constant
int
GSSAPI.CREDENTIALS_EXPIRED
constant
int
GSSAPI.CONTEXT_EXPIRED
constant
int
GSSAPI.FAILURE
constant
int
GSSAPI.BAD_QOP
constant
int
GSSAPI.UNAUTHORIZED
constant
int
GSSAPI.UNAVAILABLE
constant
int
GSSAPI.DUPLICATE_ELEMENT
constant
int
GSSAPI.NAME_NOT_MN
Constants for routine errors in major status codes like
GSSAPI.Error.major_status
. See RFC 2743 section 1.2.1.1. Note that
major status codes have to be masked with GSSAPI.ERROR_MASK
before comparison with these.
Brief descriptions of the flags:
Channel binding mismatch.
Unsupported mechanism requested.
Invalid name provided.
Name of unsupported type provided.
Invalid input status selector.
Token had invalid integrity check.
Specified security context expired.
Expired credentials detected.
Defective credential detected.
Defective token detected.
Failure, unspecified at GSS-API level.
GSSAPI.Error.minor_status
should provide further details.
No valid security context specified.
No valid credentials provided.
Unsupported QOP value.
Operation unauthorized.
Operation unavailable.
Duplicate credential element requested.
Name contains multi-mechanism elements.
constant
int
GSSAPI.CONTINUE_NEEDED
constant
int
GSSAPI.DUPLICATE_TOKEN
constant
int
GSSAPI.OLD_TOKEN
constant
int
GSSAPI.UNSEQ_TOKEN
constant
int
GSSAPI.GAP_TOKEN
Bitfield flags for informatory codes in major status codes like
GSSAPI.Error.major_status
. See RFC 2743 section 1.2.1.1. Any
combination of these might optionally be combined with one routine
error constant to form a major status code.
Brief descriptions of the flags:
Continuation call to routine required.
Duplicate per-message token detected.
Timed-out per-message token detected.
Reordered (early) per-message token detected.
Skipped predecessor token(s) detected.
constant
int
GSSAPI.ERROR_MASK
Bitfield mask for the routine error part of major status codes
like GSSAPI.Error.major_status
. After applying this mask, the
status values may be compared to any of the routine error
constants.
constant
int
GSSAPI.INFO_MASK
Bitfield mask for the informatory part of major status codes like
GSSAPI.Error.major_status
.
constant
string
GSSAPI.NT_HOSTBASED_SERVICE
constant
string
GSSAPI.NT_USER_NAME
constant
string
GSSAPI.NT_MACHINE_UID_NAME
constant
string
GSSAPI.NT_STRING_UID_NAME
constant
string
GSSAPI.NT_ANONYMOUS
constant
string
GSSAPI.NT_EXPORT_NAME
constant
string
GSSAPI.KRB5_NT_PRINCIPAL_NAME
OIDs on dotted-decimal form for the GSS-API mechanism-independent name types, and some selected mechanism-specific ones:
Name type for a service associated with a host computer. The syntax is service@hostname where the @hostname part may be omitted for the local host. See RFC 2743 section 4.1.
Name type for a named user on a local system. The syntax is username. See RFC 2743 section 4.2.
Name type for a numeric user identifier corresponding to a user on a local system. The string representing a name of this type should contain a locally-significant user ID, represented in host byte order. See RFC 2743 section 4.3.
Name type for a string of digits representing the numeric user identifier of a user on a local system. This name type is similar to the Machine UID Form, except that the buffer contains a string representing the user ID. See RFC 2743 section 4.4.
Name type to identify anonymous names. See RFC 2743 section 4.5.
Name type for the Mechanism-Independent Exported Name Object
type, which is the type of the names returned by
GSSAPI.Name.export
. See RFC 2743 section 4.7.
Name type for a Kerberos principal. See RFC 1964 section 2.1.1.
string
describe_services(int
services
)
Returns a string that compactly describes the given services
,
which is taken as a bitfield of GSSAPI.*_FLAG flags.
The returned string contains capitalized names for the flags
reminiscent of the GSSAPI.*_FLAG
constants, separated by
"|"
.
multiset
(string
) indicate_mechs()
Returns the OIDs for the available mechanism in the GSS-API implementation. The OIDs are returned on dotted-decimal form.
This wraps GSS_Indicate_mechs according to RFC 2743 section 2.4.2.
array
(string
) major_status_messages(int
major_status
)
Given a major status code like GSSAPI.Error.major_status
(or
more commonly GSSAPI.Context.last_major_status
in this case),
returns an array containing messages for all the status values in
it. The returned string(s) presumably don't end with linefeeds.
This wraps GSS_Display_status according to RFC 2743 section 2.4.1.
array
(string
) minor_status_messages(int
minor_status
, void
|string
mech
)
Given a mechanism-specific minor status code like
GSSAPI.Error.minor_status
, returns an array containing messages
for all the status values in it. The returned string(s) presumably
don't end with linefeeds.
This wraps GSS_Display_status according to RFC 2743 section 2.4.1.
minor_status
The mechanism-specific minor status.
mech
The mechanism that produced the status code. If this is zero or left out, a system default mechanism is used.
multiset
(string
) names_for_mech(string
mech
)
Returns the OIDs for the name types that the given mech
supports. Both mech
and the returned OID strings are on
dotted-decimal form.
This wraps GSS_Inquire_names_for_mech according to RFC 2743 section 2.4.12.
Variant of Context
which is used on the acceptor side.
inherit Context : Context
string
accept(string
remote_token
)
Accepts a remotely initiated security context.
This wraps GSS_Accept_sec_context according to RFC 2743 section 2.2.2.
The underlying mechanism might require several tokens to be
passed back and forth to establish the context. If
is_established
returns zero after a call to this function
then the caller must wait for a token from the remote peer to
feed as remote_token
in another call to this function.
remote_token
A token from the remote peer, as returned by a call to
GSSAPI.InitContext.init
or some other
GSS_Init_sec_context wrapper.
If a string is returned then it must be passed to the remote
peer which will feed it to GSSAPI.InitContext.init
or some
other GSS_Init_sec_context wrapper. An empty string is
never returned.
Zero is returned if there is no token to send to the remote
peer. Note that is_established
might still return zero in
that case, meaning more remote tokens are necessary.
This function might block on network connections to remote authentication servers.
GSSAPI.AcceptContext GSSAPI.AcceptContext(
void
|Cred
cred
, void
|int
required_services
)
Creates a context for acceptor use. This function only accepts
parameters to be used later during the accept
call. If there
are semantic problems with them, such as if the credentials are
stale, then they will be signalled later by accept
.
cred
Credentials for the identity this context claims. The credentials for the default principal (if any) is used if zero or left out.
required_services
Bitfield of GSSAPI.*_FLAG flags specifying all services
that must be provided in the context. If the context fail to
provide any of them then it is closed and a
GSSAPI.MissingServicesError
is thrown.
GSSAPI.PROT_READY_FLAG
is ignored in this parameter. The fact
that a user calls a per-message function indicates that this
service is required at that point, and a
GSSAPI.MissingServicesError
is thrown if it isn't.
Channel bindings (RFC 2743 section 1.1.6) are not yet implemented since that feature appear to not be in much active use, and its format is not completely specified (RFC 2744 section 3.11).
Cred
delegated_cred()
Returns the delegated credentials from the initiator if the
delegation (c.f. GSSAPI.DELEG_FLAG
) service is in use.
Class representing a security context; see RFC 2743 section 1.1.3 The
user usually instantiates one of the two inheriting classes
GSSAPI.InitContext
or GSSAPI.AcceptContext
, based on whether
the context should act as initiator or acceptor for the
connection. This class is instantiated directly for imported
contexts.
If a Context
object for a partly or completely established
context is destructed, GSS_Delete_sec_context
(RFC 2743 section 2.2.3) is called. That function might do blocking
network I/O, which due to pike's object management might occur
essentially anytime in any thread if the object isn't explicitly
destructed. To avoid that, it's strongly recommended to call
delete
in contexts that are no longer used.
GSSAPI.Context GSSAPI.Context(
string
interprocess_token
, void
|int
required_services
)
Creates a context by importing an inter-process token.
This wraps GSS_Import_sec_context according to RFC 2743 section 2.2.9.
interprocess_token
The inter-process token which has been created by export
or
some other GSS_Export_sec_context wrapper.
required_services
Bitfield of GSSAPI.*_FLAG flags specifying all services
that must be provided in the context. If the context fail to
provide any of them then it is closed and a
GSSAPI.MissingServicesError
is thrown.
GSSAPI.PROT_READY_FLAG
is ignored in this parameter. The fact
that a user calls a per-message function indicates that this
service is required at that point, and a
GSSAPI.MissingServicesError
is thrown if it isn't.
It is not possible to retrieve delegated credentials from an imported context. That is a GSS-API limitation.
void
delete()
Frees the resources for the context, provided it is in use. Does nothing otherwise.
This wraps GSS_Delete_sec_context according to RFC 2743 section 2.2.3.
This function might block on network connections to remote authentication servers.
In compliance with recommendations in GSS-API v2, the optional output token is never used in the call to GSS_Delete_sec_context.
string
export()
Exports this context so that it can be imported in another
process, providing the inter-process context transfer service is
available (c.f. GSSAPI.TRANS_FLAG
).
This wraps GSS_Export_sec_context according to RFC 2743 section 2.2.8.
The returned string is intended to be fed to
GSSAPI.Context.create
(or some other
GSS_Import_sec_context wrapper) in the receiving process.
This operation frees the context in this object.
string
get_mic(string
message
, void
|int
qop
)
Calculates and returns a MIC (message integrity checksum) for
the given message that allows the receiver to verify its origin
and integrity through verify_mic
or some other
GSS_VerifyMIC wrapper.
This wraps GSS_GetMIC according to RFC 2743 section 2.3.1.
This function requires that the context is established, or that
the early per-message protection service is available (c.f.
GSSAPI.PROT_READY_FLAG
. If not, a
GSSAPI.MissingServicesError
is thrown (but the context is not
closed).
message
The message for which the MIC is to be calculated. It may be of zero length.
qop
The quality of protection. This is a mechanism-specific value that lets the user direct how the underlying mechanism calculates the MIC. See RFC 2743 section 1.2.4.
Zero or left out means use the default method.
int
is_established()
int
services()
int
locally_initiated()
Name
source_name()
Name
target_name()
int(0..)
lifetime()
string
mech()
Functions to query various properties about the context.
These wrap GSS_Inquire_context according to RFC 2743 section 2.2.6.
Returns nonzero as soon as the context has been established.
That means no further rounds through
GSSAPI.InitContext.init
or GSSAPI.AcceptContext.accept
,
that the remote peer is authenticated as required, and that
the set of available services is complete (see services
).
Returns a bitfield of GSSAPI.*_FLAG flags for the
services that the context (currently) provides. This field is
complete only when the context establishment has finished,
i.e. when is_established
returns nonzero.
See also GSSAPI.describe_services
.
Returns nonzero if the context is an initiator, zero if it is an acceptor. (This is mainly useful in imported contexts.)
Returns the name of the context initiator. The name is always
an MN. Returns an anonymous name if used on the acceptor side
and the anonymous authentication service (c.f.
GSSAPI.ANON_FLAG
) was used.
Returns the name of the context acceptor. If a name is returned then it is always an MN.
Zero is returned on the initiator side if the initiator didn't
specify a target name and the acceptor did not authenticate
itself (should never happen if mutual authentication (c.f.
GSSAPI.MUTUAL_FLAG
) is a required service).
The returned object is not necessarily the same one as was
passed to GSSAPI.InitContext.create
, even though they are
likely to compare as equal (they might not be equal if the
passed name wasn't an MN).
Returns the validity lifetime left for the context. Returns
zero if the context has expired, or Int.inf
if there is no
time limit (in older pikes without Int.inf
a large positive
integer is returned instead).
Returns the mechanism that provides the context. The returned value is its OID on dotted-decimal form.
These functions don't throw errors if the context is missing or not completely established, even though they might not be able to query the proper values then (GSS-API implementations are known to not be completely reliable in handling these queries for partly established contexts). The functions instead return zero.
int
last_confidential()
Returns nonzero if the last call to wrap
or unwrap
provided
confidentiality for the message, i.e. if wrap
encrypted it or
if unwrap
decrypted it. Zero is returned otherwise.
int
last_major_status()
int
last_minor_status()
Returns the major and minor status codes from the last operation that called a GSS-API routine, with the exception of those that wrap GSS_Inquire_context.
int
last_qop()
Returns the quality of protection provided by the last call to
verify_mic
or unwrap
.
void
process_token(string
remote_token
)
Passes the given remote_token
to the mechanism.
This wraps GSS_Process_context_token according to RFC 2743 section 2.2.4.
This is used for tokens that are received outside the
handshaking between GSS_Init_sec_context
(GSSAPI.InitContext.init
) and GSS_Accept_sec_context
(GSSAPI.AcceptContext.accept
).
An example is when GSSAPI.InitContext.init
returns a final
token and flags the context as established, but the acceptor
context detects an error and sends a failure token back. That
token is processed using this function since
GSSAPI.InitContext.init
doesn't handle any more tokens by
then.
This function might change context state.
This function might block on network connections to remote authentication servers. However, if the remote token is the result of GSS_Delete_sec_context on the remote side then it will not block.
int
required_services(void
|int
services
)
Gets and optionally sets the set of services that must be provided in the context. The returned and given value is a bitfield of the GSSAPI.*_FLAG constants.
This is mainly useful to change the per-message service flags that
verify_mic
and unwrap
use to decide whether a condition is
an error or not.
services
New set of required services. If this is not given then the set is not changed.
If the context is established and services
contain a service
which isn't currently provided then the context is closed and a
GSSAPI.MissingServicesError
is thrown immediately.
GSSAPI.PROT_READY_FLAG
is ignored in this parameter.
Returns the current set of required services (after setting them
to services
, if provided).
GSSAPI.describe_services
string
unwrap(string
message
, void
|int
accept_encrypted_only
)
Verifies the origin and integrity of the given message using the
MIC included in it, and also decrypts the message if it was
encrypted. The message has been calculated by the sender using
wrap
or some other GSS_Wrap wrapper.
This wraps GSS_Unwrap according to RFC 2743 section 2.3.4.
This function requires that the context is established, or that
the early per-message protection service is available (c.f.
GSSAPI.PROT_READY_FLAG
. If not, a
GSSAPI.MissingServicesError
is thrown (but the context is not
closed).
message
The message to be unwrapped.
accept_encrypted_only
If this is nonzero then it is an error if message
isn't
encrypted, and zero is returned in that case (the status
returned by last_major_status
will still indicate success,
though).
Zero is returned if the verification fails with
GSSAPI.DEFECTIVE_TOKEN
or GSSAPI.BAD_MIC
.
Zero is also returned if message
isn't encrypted and
accept_encrypted_only
is set.
Otherwise the message is successfully decrypted (provided it was
encrypted to begin with), and its origin and integrity checks
out, but it might still be considered wrong depending on whether
the replay detection or sequencing services are required (see
required_services
):
If replay detection (c.f. GSSAPI.REPLAY_FLAG
) is required
then zero is returned if the message is duplicated
(GSSAPI.DUPLICATE_TOKEN
) or old (GSSAPI.OLD_TOKEN
).
If sequencing (c.f. GSSAPI.SEQUENCE_FLAG
) is required then in
addition to the replay detection conditions, zero is also
returned if the message is out of sequence
(GSSAPI.UNSEQ_TOKEN
or GSSAPI.GAP_TOKEN
).
Otherwise the unwrapped message is returned, which is valid
according to the currently required services (note however that
requiring the confidentiality service does not imply that an
error is signalled whenever an unencrypted message is received -
see instead accept_encrypted_only
above).
Any GSS-API errors except GSSAPI.DEFECTIVE_TOKEN
and
GSSAPI.BAD_MIC
are thrown.
This function sets the value returned by last_confidential
and last_qop
.
Even if the message is considered valid by the return value,
last_major_status
may be called to check for the informatory
codes mentioned above.
int
verify_mic(string
message
, string
mic
)
Verifies the origin and integrity of the given message
using
the given mic
, which has been calculated by the sender using
get_mic
or some other GSS_GetMIC wrapper.
This wraps GSS_VerifyMIC according to RFC 2743 section 2.3.2.
This function requires that the context is established, or that
the early per-message protection service is available (c.f.
GSSAPI.PROT_READY_FLAG
. If not, a
GSSAPI.MissingServicesError
is thrown (but the context is not
closed).
Zero is returned if the verification fails with
GSSAPI.DEFECTIVE_TOKEN
or GSSAPI.BAD_MIC
.
Otherwise the message origin and integrity checks out, but it
might still be considered wrong depending on whether the replay
detection or sequencing services are required (see
required_services
):
If replay detection (c.f. GSSAPI.REPLAY_FLAG
) is required
then zero is returned if the message is duplicated
(GSSAPI.DUPLICATE_TOKEN
) or old (GSSAPI.OLD_TOKEN
).
If sequencing (c.f. GSSAPI.SEQUENCE_FLAG
) is required then in
addition to the replay detection conditions, zero is also
returned if the message is out of sequence
(GSSAPI.UNSEQ_TOKEN
or GSSAPI.GAP_TOKEN
).
Otherwise nonzero is returned to indicate that the message is valid according to the currently required services.
Any GSS-API errors except GSSAPI.DEFECTIVE_TOKEN
and
GSSAPI.BAD_MIC
are thrown.
This function sets the value returned by last_qop
.
Regardless whether the message is considered valid or not by the
return value, last_major_status
may be called to check for
routine errors or the informatory codes mentioned above.
string
wrap(string
message
, void
|int
encrypt
, void
|int
qop
)
Calculates a MIC (message integrity checksum) for the given
message, and returns it together with the message, which is
optionally encrypted. The returned value can be verified and (if
applicable) decrypted by the receiver using unwrap
or some
other GSS_Unwrap wrapper.
This wraps GSS_Wrap according to RFC 2743 section 2.3.3.
This function requires that the context is established, or that
the early per-message protection service is available (c.f.
GSSAPI.PROT_READY_FLAG
. If not, a
GSSAPI.MissingServicesError
is thrown (but the context is not
closed).
message
The message to be wrapped. It may be of zero length.
encrypt
Set to nonzero to request that the message is encrypted. Otherwise only a MIC is calculated and the returned value contains the unencrypted message.
If this is set and the confidentiality service (c.f.
GSSAPI.CONF_FLAG
) is required then the returned value is
always encrypted. Otherwise it might not be encrypted anyway,
and a call to last_confidential
will tell if it is or not.
qop
The quality of protection. This is a mechanism-specific value that lets the user direct how the underlying mechanism calculates the MIC. See RFC 2743 section 1.2.4.
Zero or left out means use the default method.
This function sets the value returned by last_confidential
.
wrap_size_limit
int(0..)
wrap_size_limit(int(0..)
output_size
, int
encrypt
, void
|int
qop
)
Returns the maximum size of an input string to wrap
that
would produce no more than output_size
bytes in the resulting
output.
This wraps GSS_Wrap_size_limit according to RFC 2743 section 2.2.7.
with_confidentiality
and qop
are the same as in the call
to wrap
.
Objects of this class hold one or more credentials that the current process can use to assert identities; see RFC 2743 section 1.1.1.
If a Cred
object is destructed, GSS_Release_cred
(RFC 2743 section 2.1.2) is called. The RFC doesn't preclude that
that function might do blocking network I/O, which due to pike's
object management might occur essentially anytime in any thread
if the object isn't explicitly destructed. To avoid that, it's
recommended to call release
in credential objects that are no
longer used.
GSSAPI.Name
name(void
|string
mech
)
int
cred_usage(void
|string
mech
)
multiset
(string
) mechs()
int(0..)
|Int.inf
lifetime()
int(0..)
|Int.inf
init_lifetime(string
mech
)
int(0..)
|Int.inf
accept_lifetime(string
mech
)
Functions to query various properties about the credentials.
These wrap GSS_Inquire_cred according to RFC 2743 section 2.1.3
if mech
is not given, and GSS_Inquire_cred_by_mech
according to RFC 2743 section 2.1.5 otherwise.
mech
If this is given then the credential for that specific
mechanism is queried. mech
contains the OID of the
mechanism on dotted-decimal form.
Some of the query functions can only be used for a specific
mechanism, in which case mech
is required. Some can only be
used on the credentials in general, and the mech
argument
is not applicable. Some can be used both ways, and then
mech
is optional.
name (void|string mech)
Returns the name of the identity that the credential(s)
assert. If mech
is given then the returned name is a
Mechanism Name (MN).
The returned GSSAPI.Name
object is always a newly created
one, even though it typically compares as equal with the ones
given to acquire
or add
.
cred_usage (void|string mech)
Returns how the credential(s) may be used, one of
GSSAPI.INITIATE
, GSSAPI.ACCEPT
or GSSAPI.BOTH
.
If mech
is not given then the returned usage value reflects
the union of the capabilities in all credentials.
mechs() Returns the set of mechanisms supported by the credential. The returned value is a multiset of strings with OIDs on dotted-decimal form.
lifetime() Returns the shortest validity lifetime left in any of the mechanisms that are part of the credentials, for either initiator or acceptor use.
Returns zero if some part of the credentials has expired.
Returns Int.inf
if there is no time limit (in older pikes
without Int.inf
a large positive integer is returned
instead).
init_lifetime (string mech) Returns the validity lifetime left for initiator use.
Returns zero if the credential has expired for this use or if
its usage is GSSAPI.ACCEPT
.
Returns Int.inf
if there is no time limit (in older pikes
without Int.inf
a large positive integer is returned
instead).
accept_lifetime (string mech) Returns the validity lifetime left for acceptor use.
Returns zero if the credential has expired for this use or if
its usage is GSSAPI.INITIATE
.
Returns Int.inf
if there is no time limit (in older pikes
without Int.inf
a large positive integer is returned
instead).
RFC 2743 doesn't preclude that these functions might block on network connections to remote authentication servers.
void
acquire(Name
|string
name
, int
cred_usage
, void
|multiset
(string
) desired_mechs
, void
|int(0..)
desired_time
)
Acquire initial credentials for this object. It is an error if it already has some credentials.
This wraps GSS_Acquire_cred according to RFC 2743 section 2.1.1.
name
The name of the identity for which credentials should be acquired. It is up to the GSS-API implementation to check whether the running process is authorized to act on behalf of this identity.
This can be either a GSSAPI.Name
object or a string. In the
latter case, the string is converted to a GSS-API name
according to a mechanism-specific default printable syntax,
i.e. just like if it would be given as the sole argument to
GSSAPI.Name.create
.
If this is zero then credentials for the default principal (if any) are retrieved.
cred_usage
Specifies how the credential will be used. One of
GSSAPI.INITIATE
, GSSAPI.ACCEPT
or GSSAPI.BOTH
.
desired_mechs
The mechanisms that the credentials should cover, as a multiset containing their OIDs on dotted-decimal form. If zero or left out then a default set provided by the GSS-API implementation is used.
It is an error to pass an empty multiset.
desired_time
Number of seconds the credentials should remain valid. The GSS-API implementation may return credentials that are valid both longer and shorter than this. Zero or left out means use the maximum permitted time.
This function might block on network connections to remote authentication servers.
void
add(Name
|string
name
, int
cred_usage
, string
desired_mech
, void
|int(0..)
|array
(int(0..)
) desired_time
)
Adds another credential element to this object. If this object has no credentials already then it will get the default credentials in addition to this specified one.
This wraps GSS_Add_cred according to RFC 2743 section 2.1.4.
name
The name of the identity for which a credential should be acquired. It is up to the GSS-API implementation to check whether the running process has sufficient privileges to act on behalf of this identity.
This can be either a GSSAPI.Name
object or a string. In the
latter case, the string is converted to a GSS-API name
according to a mechanism-specific default printable syntax,
i.e. just like if it would be given as the sole argument to
GSSAPI.Name.create
.
If this is zero then a credential for the default principal (if any) are retrieved.
cred_usage
Specifies how the credential will be used. One of
GSSAPI.INITIATE
, GSSAPI.ACCEPT
or GSSAPI.BOTH
.
desired_mech
The mechanism that the credential should cover, as an OID on dotted-decimal form.
desired_time
Number of seconds the credential should remain valid. The GSS-API implementation may return a credential that is valid both longer and shorter than this. Zero or left out means use the maximum permitted time.
This can also be an array containing two elements. In that case the first element applies to the credential when it is used to initiate contexts, and the second element applies to use for acceptor contexts.
This function might block on network connections to remote authentication servers.
void
release()
Frees the resources for the credential.
This wraps GSS_Release_cred according to RFC 2743 section 2.1.2.
This function might block on network connections to remote authentication servers.
Error object used for GSS-API errors.
inherit Error.Generic : Generic
constant
int
GSSAPI.Error.is_gssapi_error
constant
string
GSSAPI.Error.error_type
Object recognition constants.
int
GSSAPI.Error.major_status
The major status code. This is a bitwise OR of one routine error code and zero or more supplementary error info bits.
See RFC 2743 section 1.2.1.1 and RFC 2744 section 3.9.1. Note that the calling errors mentioned in RFC 2744 are never thrown.
major_status_messages
int
GSSAPI.Error.minor_status
The minor status code specific for the mechanism.
minor_status_messages
, minor_status_mech
GSSAPI.Error GSSAPI.Error(
void
|int
major
, void
|int
minor
, void
|string
mech
, void
|string
message
, void
|array
backtrace
)
major
Initial value for major_status
.
minor
Initial value for minor_status
.
mech
Object identifier on dotted-decimal form for the mechanism that
minor
applies to.
message
Error message. This is prepended to the message generated from
major_status
and/or minor_status
. ": "
is inserted
in between.
backtrace
Backtrace. The current backtrace for the calling function is used if left out.
array
(string
) major_status_messages()
Returns an array containing messages for all the status values in
major_status
. See GSSAPI.major_status_messages
for further
details.
string
|zero
minor_status_mech()
Returns the OID for the mechanism that is used to interpret the minor status, or zero if no mechanism has been set. It is returned on dotted-decimal form.
array
(string
) minor_status_messages()
Returns an array containing messages for all the status values in
minor_status
. See GSSAPI.minor_status_messages
for further
details.
Variant of Context
which is used on the initiator side.
inherit Context : Context
GSSAPI.InitContext GSSAPI.InitContext(
void
|Cred
cred
, void
|Name
|string
target_name
, void
|string
mech
, void
|int
required_services
, void
|int
desired_services
, void
|int(0..)
desired_time
)
Creates a context for initiator use. This function only accepts
parameters to be used later during the init
call. If there
are semantic problems with them, such as if the credentials are
stale or the mechanism isn't supported, then they will be
signalled later by init
.
cred
Credentials for the identity this context claims. The credentials for the default principal (if any) is used if zero or left out.
target_name
The name of the target.
This can be either a GSSAPI.Name
object or a string. In the
latter case, the string is converted to a GSS-API name
according to a mechanism-specific default printable syntax,
i.e. just like if it would be given as the sole argument to
GSSAPI.Name.create
.
Some mechanisms support unnamed targets (as allowed in GSS-API v2, update 1) and in such cases this may be zero or left out.
mech
The mechanism to use. It is given as an OID on dotted-decimal form. The GSS-API implementation chooses this using system settings if it's zero or left out, which is the recommended way.
required_services
Bitfield of GSSAPI.*_FLAG flags specifying all services
that must be provided in the context. If the context fail to
provide any of them then it is closed and a
GSSAPI.MissingServicesError
is thrown.
GSSAPI.PROT_READY_FLAG
is ignored in this parameter. The fact
that a user calls a per-message function indicates that this
service is required at that point, and a
GSSAPI.MissingServicesError
is thrown if it isn't.
desired_services
Bitfield of GSSAPI.*_FLAG flags specifying the context
services that are wanted but not required. I.e. errors won't
be thrown if any of these aren't provided. The services
specified in required_services
are implicit, so they need
not be repeated here.
GSSAPI.PROT_READY_FLAG
is ignored in this parameter.
desired_time
The desired context validity time in seconds. Zero or left out means use the default.
Channel bindings (RFC 2743 section 1.1.6) are not yet implemented since that feature appear to not be in much active use, and its format is not completely specified (RFC 2744 section 3.11).
string
init(void
|string
remote_token
)
Initiates a security context to send to a remote peer.
This wraps GSS_Init_sec_context according to RFC 2743 section 2.2.1.
The underlying mechanism might require several tokens to be
passed back and forth to establish the context. If
is_established
returns zero after a call to this function
then the caller must wait for a token from the remote peer to
feed as remote_token
in another call to this function.
remote_token
A token from the remote peer, as returned by a call to
GSSAPI.AcceptContext.accept
(or some other
GSS_Accept_sec_context wrapper) in it. This is zero or
left out on the initial call, but used later if the remote
peer sends back tokens to process as part of the context
establishment.
If a string is returned then it must be passed to the remote
peer which will feed it to GSSAPI.AcceptContext.accept
or
some other GSS_Accept_sec_context wrapper. An empty
string is never returned.
Zero is returned if there is no token to send to the remote
peer. Note that is_established
might still return zero in
that case, meaning more remote tokens are necessary.
This function might block on network connections to remote authentication servers.
Error object used when one or more required services are missing
in a GSSAPI.Context
object.
inherit Error.Generic : Generic
constant
int
GSSAPI.MissingServicesError.is_gssapi_missing_services_error
constant
string
GSSAPI.MissingServicesError.error_type
Object recognition constants.
int
GSSAPI.MissingServicesError.services
Bitfield of GSSAPI.*_FLAG flags for the missing services that caused the error.
GSSAPI.describe_services
GSSAPI.MissingServicesError GSSAPI.MissingServicesError(
void
|int
missing_services
)
missing_services
Initial value for services
.
An object of this class contains a name on the internal form which is required by the GSS-API functions. See RFC 2743 section 1.1.5.
int
hash_value( GSSAPI.Name arg )
Tries to export the name (see export
) and if that succeeds
returns a hash made from the exported name string. Otherwise a
normal hash based on this object is returned.
This means that mechanism names (MNs) can be used as indices in mappings without getting duplicate entries for the same identity.
int
res = GSSAPI.Name()
== other
Returns true if other
is a GSSAPI.Name
which contains a
name that refers to the same identity as this one.
This wraps GSS_Compare_name according to RFC 2743 section 2.4.3.
If either GSSAPI.Name
object is uninitialized or contains an
anonymous identity then they are considered different, unless it
is the very same GSSAPI.Name
object (that is an inherent pike
behavior).
An error is thrown if the names are incomparable, or if either of them are ill-formed.
Name
canonicalize(string
mech
)
Returns a GSSAPI.Name
containing the canonical mechanism name
(MN) of this name. The mechanism is given as a dotted-decimal
OID in mech
.
This wraps GSS_Canonicalize_name according to RFC 2743 section 2.4.14.
This function might block on network connections to remote authentication servers.
GSSAPI.Name GSSAPI.Name(
string
name
, void
|string
name_type
)
This wraps GSS_Import_name according to RFC 2743 section 2.4.5.
name
A name on string form (a contiguous string name in GSS-API parlance).
name_type
The OID on dotted-decimal form for the type of the name in
name
. If left out, name
is parsed according to a
mechanism-specific default printable syntax.
If name
is the result of export
or a similar function
then name_type
should be GSSAPI.NT_EXPORT_NAME
.
string
display_name()
string
display_name_type()
display_name
returns a representation of the name for display
purposes, and display_name_type
returns an OID on
dotted-decimal form for the type of that name.
If no type was given to create
then display_name_type
might return zero.
This wraps GSS_Display_name according to RFC 2743 section 2.4.4.
The GSSAPI.NT_* constants.
string
export(void
|string
mech
)
Returns the name on the exported format. If mech
isn't given
then the name has to be a mechanism name (MN). If mech
is
given then the name is canonicalized according to that mechanism
before being exported (see canonicalize
).
This wraps GSS_Export_name according to RFC 2743 section 2.4.15.
This function might block on network connections to remote
authentication servers if mech
is specified.
multiset
(string
) mechs()
Returns the OIDs for the mechanisms that might be able to process this name. The returned OID strings are on dotted-decimal form.
This wraps GSS_Inquire_mechs_for_name according to RFC 2743 section 2.4.13.
Some older GSS-API v2 implementations lack this funcion.
Various cryptographic classes and functions.
These are based on the Nettle.Hash
API.
Examples include MD5
, SHA1
, SHA256
and SHA3_256
.
These are based on the Nettle.Cipher
API.
Examples include AES
, Arcfour
, DES
, DES3
, CAMELLIA
.
The Substitution
program is compatible with Cipher.State
.
Also conforming to the API are several helper modules such as
predef::Nettle.BufferedCipher.Buffer
,
predef::Nettle.BlockCipher.CBC
,
predef::Nettle.BlockCipher16.GCM
and Pipe
.
MAC
algorithms are provided as sub-modules to their corresponding
Hash
or Cipher
module.
Examples include SHA1.HMAC
and AES.UMAC32
.
AEAD
s combine ciphers with authentication codes, and may optionally
also take into account some associated data that is provided out of band.
This API is compatible with both Cipher
and Hash
.
AEADs are provided as sub-modules to their corresponding ciphers.
Examples include AES.CCM
, AES.GCM
and CAMELLIA.EAX
.
As the cryptographic services offered from this module aren't necessarily used for security applications, none of the strings input or output are marked as secure. That is up to the caller.
Most of the APIs in this module work on 8 bit binary strings unless
otherwise noted.
For conversions to and from hexadecimal notation String.string2hex()
and String.hex2string()
may be of interest.
This module is only available if Pike has been compiled with
Nettle
enabled (this is the default).
string(8bit)
make_crypt_md5(string(8bit)
password
, string(8bit)
|void
salt
)
Hashes a password
together with a salt
with the
crypt_md5 algorithm and returns the result.
verify_crypt_md5
string(8bit)
rot13(string(8bit)
data
)
Convenience function that accesses the crypt function of a substitution object keyed to perform standard ROT13 (de)ciphering.
int
siphash24(string
data
, void
|int
key
)
Hashes a string, with an optional key, to a 64 bit integer using
the siphash-2-4 algorithm. Currently the 64 bit key
parameter
is used both for the high and low part of the 128 bit key.
bool
verify_crypt_md5(string(8bit)
password
, string(7bit)
hash
)
Verifies the password
against the crypt_md5 hash.
May throw an exception if the hash value is bad.
make_crypt_md5
Abstract class for AE algorithms.
inherit __builtin.Nettle.AE : AE
Abstract class for AEAD algorithms.
inherit Nettle.AEAD : AEAD
Abstract class for block cipher algorithms. Contains some tools useful for all block ciphers.
Contains the CBC
submodule.
inherit Nettle.BlockCipher : BlockCipher
Abstract class for block cipher algorithms with a 16 byte block size. Contains some tools useful for all such block ciphers.
Contains the GCM
submodule.
inherit Nettle.BlockCipher16 : BlockCipher16
Abstract class for block cipher meta algorithms.
Contains the Buffer
submodule.
inherit Nettle.BufferedCipher : BufferedCipher
Abstract class for crypto algorithms. Contains some tools useful for all ciphers.
Typically only inherited directly by stream ciphers.
It is however convenient for typing as it contains the minimum base level API for a cipher.
BufferedCipher
, BlockCipher
, BlockCipher16
inherit Nettle.Cipher : Cipher
HMAC, defined by RFC 2104.
Backward-compatibility implementation. New code should
use Crypto.Hash.HMAC
.
Crypto.MAC.State
res = Crypto.HMAC()
()
Calling the HMAC object with a password returns a new object that
can perform the actual HMAC hashing. E.g. doing a HMAC hash with
MD5 and the password "bar"
of the string "foo"
would require the code Crypto.HMAC(Crypto.MD5)("bar")("foo")
.
Crypto.HMAC Crypto.HMAC(
.Hash
h
, int(1..)
|void
b
)
h
The hash object on which the HMAC object should base its
operations. Typical input is Crypto.MD5
.
b
The block size of one compression block, in octets. Defaults to
block_size() of h
.
string(8bit)
pkcs_digest(string(8bit)
s
)
Makes a PKCS-1 digestinfo block with the message s
.
Standards.PKCS.Signature.build_digestinfo
string(8bit)
raw_hash(string(8bit)
s
)
Calls the hash function given to create
and returns the hash
value of s
.
Abstract class for hash algorithms. Contains some tools useful for all hashes.
inherit Nettle.Hash : Hash
Abstract class for Message Authentication Code (MAC) algorithms. Contains some tools useful for all MACs.
inherit Nettle.MAC : MAC
A wrapper class that connects several cipher algorithms into one
algorithm. E.g. triple DES can be emulated with
Crypto.Pipe(Crypto.DES, Crypto.DES, Crypto.DES)
.
Abstract class for signature algorithms. Contains some tools useful for all signatures.
State
res = Crypto.Sign()
()
Calling `() will return a State
object.
string(7bit)
name()
Returns the printable name of the signing algorithm.
inherit __builtin.Nettle.Sign : Sign
Implements a simple substitution crypto, ie. one of the first crypto systems ever invented and thus one of the least secure ones available.
string(8bit)
decrypt(string(8bit)
c
)
Decrypts the cryptogram c
.
string(8bit)
encrypt(string(8bit)
m
)
Encrypts the message m
.
string
filter(string
m
, multiset
(int
)|void
save
)
Removes characters not in the encryption key or in
the save
multiset from the message m
.
this_program
set_ACA_K1_key(string
key
, void
|int
offset
, array
(string
)|void
alphabet
)
Sets the key according to ACA K1 key generation. The plaintext
alphabet is prepended with a keyword key
that shifts the alphabet
positions compared to the cryptogram alphabet. The plaintext
alphabet is then reduced with the characters in the keyword. It is
also optionally rotated offset
number of steps.
this_program
set_ACA_K2_key(string
key
, void
|int
offset
, array
(string
)|void
alphabet
)
Sets the key according to ACA K2 key generation. The cryptogram
alphabet is prepended with a keyword key
that shifts the alphabet
positions compared to the plaintext alphabet. The cryptogram
alphabet is then reduced with the characters in the keyword. It is
als optionally reotated offset
number of steps.
this_program
set_ACA_K3_key(string
key
, int
offset
, array
(string
)|void
alphabet
)
Sets the key according to ACA K3 key generation. Both the plaintext
and the cryptogram alphabets are prepended with a keyword key
,
which characters are removed from the rest of the alphabet. The
plaintext alphabet is then rotated offset
number of steps.
this_program
set_ACA_K4_key(string
key1
, string
key2
, void
|int
offset
, array
(string
)|void
alphabet
)
Sets the key according to ACA K4 key generation. Both the plaintext
and the cryptogram alphabets are prepended with the keywords key1
and key2
. The plaintext alphabet is then rotated offset
number
of steps.
this_program
set_key(mapping
(string
:string
|array
(string
)) key
)
Sets the encryption and decryption key. The decryption key is
derived from the encryption key
by reversing the mapping. If
one index maps to an array of strings, one element from the array
will be chosen at random in such substitution.
An error is thrown if the encryption key can not be made reversible.
this_program
set_null_chars(int
|float
p
, array
(string
) chars
)
Set null characters (fillers). Characters from chars
will be
inserted into the output stream with a probability p
.
p
A float between 0.0 and 1.0 or an integer between 0 and 100.
chars
An array of one character strings.
this_program
set_rot_key(int(1..)
|void
steps
, void
|array
(string
) alphabet
)
Sets the key to a ROT substitution system. steps
defaults
to 13 and alphabet
defaults to A-Z, i.e. this function
defaults to set the substitution crypto to be ROT13. If no
alphabet is given the key will be case insensitive, e.g. the
key will really be two ROT13 alphabets, one a-z and one A-Z,
used simultaneously.
AES (American Encryption Standard) is a quite new block cipher, specified by NIST as a replacement for the older DES standard. The standard is the result of a competition between cipher designers. The winning design, also known as RIJNDAEL, was constructed by Joan Daemen and Vincent Rijnmen.
Like all the AES candidates, the winning design uses a block size of 128 bits, or 16 octets, and variable key-size, 128, 192 and 256 bits (16, 24 and 32 octets) being the allowed key sizes. It does not have any weak keys.
inherit Nettle.AES : AES
inherit Nettle.POLY1305_AES : POLY1305_AES
protected
State
`()(string(8bit)
password
)
Get a POLY1305 State
object initialized with a password.
UMAC is a familty of message digest functions based on universal
hashing and AES
that is specified in RFC 4418. They differ
mainly in the size of the resulting digest.
UMAC128
outputs a digest of 128 bits or 16 octets.
UMAC32
, UMAC64
, UMAC96
inherit Nettle.UMAC128_AES : UMAC128_AES
protected
State
`()(string(8bit)
password
)
Get a UMAC128 State
object initialized with a password.
UMAC is a familty of message digest functions based on universal
hashing and AES
that is specified in RFC 4418. They differ
mainly in the size of the resulting digest.
UMAC32
outputs a digest of 32 bits or 4 octets.
UMAC64
, UMAC96
, UMAC128
inherit Nettle.UMAC32_AES : UMAC32_AES
protected
State
`()(string(8bit)
password
)
Get a UMAC32 State
object initialized with a password.
UMAC is a familty of message digest functions based on universal
hashing and AES
that is specified in RFC 4418. They differ
mainly in the size of the resulting digest.
UMAC64
outputs a digest of 64 bits or 8 octets.
UMAC32
, UMAC96
, UMAC128
inherit Nettle.UMAC64_AES : UMAC64_AES
protected
State
`()(string(8bit)
password
)
Get a UMAC64 State
object initialized with a password.
UMAC is a familty of message digest functions based on universal
hashing and AES
that is specified in RFC 4418. They differ
mainly in the size of the resulting digest.
UMAC96
outputs a digest of 96 bits or 12 octets.
UMAC32
, UMAC64
, UMAC128
inherit Nettle.UMAC96_AES : UMAC96_AES
protected
State
`()(string(8bit)
password
)
Get a UMAC96 State
object initialized with a password.
Arcfour is a stream cipher, also known under the trade marked name
RC4, and it is one of the fastest ciphers around. A problem is
that the key setup of Arcfour is quite weak, you should never use
keys with structure, keys that are ordinary passwords, or
sequences of keys like "secret:1"
, "secret:2"
,
..... If you have keys that don't look like random bit strings,
and you want to use Arcfour, always hash the key before feeding it
to Arcfour.
inherit Nettle.ARCFOUR : ARCFOUR
Arctwo is a block cipher, also known under the trade marked name RC2.
The cipher is quite weak, and should not be used for new software.
inherit Nettle.ARCTWO : ARCTWO
BLOWFISH is a block cipher designed by Bruce Schneier. It uses a block size of 64 bits (8 octets), and a variable key size, up to 448 bits. It has some weak keys.
inherit Nettle.BLOWFISH : BLOWFISH
CAST-128 is a block cipher, specified in RFC 2144. It uses a 64 bit (8 octets) block size, and a variable key size of up to 128 bits.
inherit Nettle.CAST128 : CAST128
The Camellia 128-bit block cipher.
inherit Nettle.CAMELLIA : CAMELLIA
ChaCha20 is a stream cipher by D. J. Bernstein.
This module is not available in all versions of Nettle.
inherit Nettle.CHACHA : CHACHA
This is an AEAD
cipher consisting of the CHACHA
cipher
and a MAC
based on the POLY1305 algorithm.
Note that this is an AEAD
cipher, while AES.POLY1305
(aka POLY1305-AES) is a MAC
.
Note also that the POLY1305 algorithm used here is NOT identical
to the one in the AES.POLY1305
MAC
. The iv/nonce handling
differs.
This module is not available in all versions of Nettle.
inherit Nettle.CHACHA_POLY1305 : CHACHA_POLY1305
Some non-cryptographic checksums.
int(0..)
adler32(string(8bit)
data
, void
|int(0..)
seed
)
This function calculates the Adler-32 Cyclic Redundancy Check.
seed
Can be fed with the result of the previous invocation to chain on new data. Defaults to zero on virgin runs.
int(0..)
crc32(string(8bit)
data
, void
|int(0..)
seed
)
This function calculates the standard ISO3309 Cyclic Redundancy Check.
seed
Can be fed with the result of the previous invocation to chain on new data. Defaults to zero on virgin runs.
int(0..)
crc32c(string(8bit)
data
, void
|int(0..)
seed
)
This function calculates the Castagnoli CRC, CRC32C. Hardware optimized on Intel CPUs with SSE 4.2.
seed
Can be fed with the result of the previous invocation to chain on new data. Defaults to zero on virgin runs.
DES is the old Data Encryption Standard, specified by NIST. It uses a block size of 64 bits (8 octets), and a key size of 56 bits. However, the key bits are distributed over 8 octets, where the least significant bit of each octet is used for parity. A common way to use DES is to generate 8 random octets in some way, then set the least significant bit of each octet to get odd parity, and initialize DES with the resulting key.
The key size of DES is so small that keys can be found by brute
force, using specialized hardware or lots of ordinary work
stations in parallel. One shouldn't be using plain DES at all
today, if one uses DES at all one should be using DES3
or "triple
DES".
DES also has some weak keys.
inherit Nettle.DES : DES
The inadequate key size of DES
has already been mentioned. One
way to increase the key size is to pipe together several DES boxes
with independent keys. It turns out that using two DES ciphers is
not as secure as one might think, even if the key size of the
combination is a respectable 112 bits.
The standard way to increase DES's key size is to use three DES boxes. The mode of operation is a little peculiar: the middle DES box is wired in the reverse direction. To encrypt a block with DES3, you encrypt it using the first 56 bits of the key, then decrypt it using the middle 56 bits of the key, and finally encrypt it again using the last 56 bits of the key. This is known as "ede" triple-DES, for "encrypt-decrypt-encrypt".
The "ede" construction provides some backward compatibility, as you get plain single DES simply by feeding the same key to all three boxes. That should help keeping down the gate count, and the price, of hardware circuits implementing both plain DES and DES3.
DES3 has a key size of 168 bits, but just like plain DES, useless parity bits are inserted, so that keys are represented as 24 octets (192 bits). As a 112 bit key is large enough to make brute force attacks impractical, some applications uses a "two-key" variant of triple-DES. In this mode, the same key bits are used for the first and the last DES box in the pipe, while the middle box is keyed independently. The two-key variant is believed to be secure, i.e. there are no known attacks significantly better than brute force.
inherit Nettle.DES3 : DES3
Diffie-Hellman key-exchange related stuff.
Parameters
Crypto.DH.FFDHE2048
Finite Field Diffie-Hellman 2048
From RFC 7919 appendix A.1.
Parameters
Crypto.DH.FFDHE2432
Finite Field Diffie-Hellman 2432
Mentioned in Negotiated FF-DHE for TLS draft 06, March 2015, Section 2.
Parameters
Crypto.DH.FFDHE3072
Finite Field Diffie-Hellman 3072
From RFC 7919 appendix A.2.
Parameters
Crypto.DH.FFDHE4096
Finite Field Diffie-Hellman 4096
From RFC 7919 appendix A.3.
Parameters
Crypto.DH.FFDHE6144
Finite Field Diffie-Hellman 6144
From RFC 7919 appendix A.4.
Parameters
Crypto.DH.FFDHE8192
Finite Field Diffie-Hellman 8192
From RFC 7919 appendix A.5.
Parameters
Crypto.DH.MODPGroup1
MODP Group 1 (768 bit) (aka First Oakley Group (aka ORM96 group 1)).
Not allowed for use with FIPS 140.
Parameters
Crypto.DH.MODPGroup14
MODP Group 14 (2048 bit).
Parameters
Crypto.DH.MODPGroup15
MODP Group 15 (3072 bit).
Parameters
Crypto.DH.MODPGroup16
MODP Group 16 (4096 bit).
Parameters
Crypto.DH.MODPGroup17
MODP Group 17 (6144 bit).
Parameters
Crypto.DH.MODPGroup18
MODP Group 18 (8192 bit).
Parameters
Crypto.DH.MODPGroup2
MODP Group 2 (1024 bit) (aka Second Oakley Group (aka ORM96 group 2)).
Not allowed for use with FIPS 140.
Parameters
Crypto.DH.MODPGroup22
MODP Group 22 (1024-bit with 160-bit Subgroup).
Parameters
Crypto.DH.MODPGroup23
MODP Group 23 (2048-bit with 224-bit Subgroup).
Parameters
Crypto.DH.MODPGroup24
MODP Group 24 (2048-bit with 256-bit Subgroup).
Parameters
Crypto.DH.MODPGroup5
MODP Group 5 (1536 bit).
Not allowed for use with FIPS 140.
Diffie-Hellman parameters.
inherit Nettle.DH_Params : DH_Params
Gmp.mpz
|zero
Crypto.DH.Parameters.g
Generator.
Gmp.mpz
|zero
Crypto.DH.Parameters.p
Prime.
Gmp.mpz
|zero
Crypto.DH.Parameters.q
Subgroup size.
Crypto.DH.Parameters Crypto.DH.Parameters(
this_program
other
)
Initialize the set of Diffie-Hellman parameters.
other
Copy the parameters from this object.
Crypto.DH.Parameters Crypto.DH.Parameters(
DSA_State
dsa
)
Initialize the set of Diffie-Hellman parameters.
dsa
Copy the parameters from this object.
Crypto.DH.Parameters Crypto.DH.Parameters(
Gmp.mpz
|int
p
, Gmp.mpz
|int
|void
g
, Gmp.mpz
|int
|void
q
)
Initialize the set of Diffie-Hellman parameters.
p
The prime for the group.
g
The generator for the group. Defaults to 2
.
q
The order of the group. Defaults to (p-1)/2
.
array
(Gmp.mpz
) generate_keypair(function
(int(0..)
:string(8bit)
) rnd
)
Generate a Diffie-Hellman key pair.
Returns the following array:
Array | |
| The generated public key. |
| The corresponding private key. |
bool
validate(int(0..)
effort
)
Validate that the DH Parameters doesn't have obvious security
weaknesses. It will first attempt to verify the prime p
using
Donald Knuth's probabilistic primality test with provided
effort
. This has a chance of pow(0.25,effort) to produce a
false positive. An effort
of 0 skipps this step. The second
test verifies that g
is of high order.
The Digital Signature Algorithm DSA is part of the NIST Digital Signature Standard DSS, FIPS-186 (1993).
inherit Crypto.Sign : Sign
protected
State
`()()
Calling `() will return a State
object.
string(7bit)
name()
Returns the string "DSA"
.
@Pike.Annotations.Implements
(Crypto.Sign.State
)
inherit ::this_program : this_program
bool
equal(Crypto.DSA.State from, mixed
other
)
Compares the keys of this DSA object with something other.
variant
this_program
generate_key()
Generates a public/private key pair. Needs the public parameters
p, q and g set, through one of set_public_key
,
generate_key(int,int)
or generate_key(params)
.
variant
this_program
generate_key(int
p_bits
, int
q_bits
)
Generates DSA parameters (p, q, g) and key (x, y). Depending on
Nettle version q_bits
can be 160, 224 and 256 bits. 160 works
for all versions.
variant
this_program
generate_key(.DH.Parameters
params
)
Generates a public/private key pair with the specified finite field diffie-hellman parameters.
Gmp.mpz
|zero
get_g()
Returns the DSA generator (g).
Gmp.mpz
|zero
get_p()
Returns the DSA modulo (p).
Gmp.mpz
|zero
get_q()
Returns the DSA group order (q).
Gmp.mpz
|zero
get_x()
Returns the DSA private key (x).
Gmp.mpz
|zero
get_y()
Returns the DSA public key (y).
Gmp.mpz
hash(string(8bit)
msg
, __builtin.Nettle.Hash
h
)
Makes a DSA hash of the message msg
.
string(7bit)
name()
Returns the string "DSA"
.
Sequence
pkcs_algorithm_identifier()
Returns the AlgorithmIdentifier as defined in RFC 5280 section 4.1.1.2 including the DSA parameters.
Sequence
pkcs_public_key()
Creates a SubjectPublicKeyInfo ASN.1 sequence for the object. See RFC 5280 section 4.1.2.7.
string(8bit)
pkcs_sign(string(8bit)
message
, __builtin.Nettle.Hash
h
)
Signs the message
with a PKCS-1 signature using hash algorithm
h
.
Sequence
|zero
pkcs_signature_algorithm_id(__builtin.Nettle.Hash
hash
)
Returns the PKCS-1 algorithm identifier for DSA and the provided
hash algorithm. Only SHA1
supported.
bool
pkcs_verify(string(8bit)
message
, __builtin.Nettle.Hash
h
, string(8bit)
sign
)
Verify PKCS-1 signature sign
of message message
using hash
algorithm h
.
bool
public_key_equal(object
other
)
Compares the public key in this object with that in the provided DSA object.
array
(Gmp.mpz
) raw_sign(Gmp.mpz
h
, Gmp.mpz
|void
k
)
Sign the message h
. Returns the signature as two Gmp.mpz
objects.
bool
raw_verify(Gmp.mpz
h
, Gmp.mpz
r
, Gmp.mpz
s
)
Verify the signature r
,s
against the message h
.
this_program
set_private_key(Gmp.mpz
secret
)
Sets the private key, the x parameter, in this DSA object.
this_program
set_public_key(Gmp.mpz
modulo
, Gmp.mpz
order
, Gmp.mpz
generator
, Gmp.mpz
key
)
Sets the public key in this DSA object.
modulo
This is the p parameter.
order
This is the group order q parameter.
generator
This is the g parameter.
kye
This is the public key y parameter.
variant
this_program
set_public_key(.DH.Parameters
params
, Gmp.mpz
key
)
Sets the public key in this DSA object.
params
The finite-field diffie-hellman group parameters.
key
The public key y parameter.
this_program
set_random(function
(int(0..)
:string(8bit)
) r
)
Sets the random function, used to generate keys and parameters, to
the function r
. Default is random_string
.
Elliptic Curve Cipher Constants.
This module contains constants used with elliptic curve algorithms.
The definition of an elliptic curve.
Objects of this class are typically not created by the user.
SECP_192R1
, SECP_224R1
, SECP_256R1
, SECP_384R1
, SECP_521R1
inherit Nettle.ECC_Curve : ECC_Curve
Sequence
pkcs_algorithm_identifier()
Returns the AlgorithmIdentifier as defined in RFC 5480 section 2.
Identifier
pkcs_ec_parameters()
Returns the PKCS-1 elliptic curve parameters for the curve. cf RFC 5480 section 2.1.1.
Identifier
|zero
pkcs_named_curve_id()
Returns the PKCS-1 elliptic curve identifier for the curve. cf RFC 5480 section 2.1.1.
Elliptic Curve Digital Signing Algorithm
inherit ECC_Curve::ECDSA : ECDSA
bool
equal(Crypto.ECC.Curve.ECDSA from, mixed
other
)
Compares the keys of this ECDSA object with something other.
this_program
generate_key()
Generate a new set of private and public keys on the current curve.
Curve
get_curve()
Return the curve.
Point
get_point()
Get the public key curve point.
string(8bit)
get_public_key()
Get the ANSI x9.62 4.3.6 encoded uncompressed public key.
array
(mapping
(string(7bit)
:string(7bit)
|int
)|string(8bit)
)|zero
jose_decode(string(7bit)
jws
)
Verify and decode a JOSE JWS ECDSA signed value.
jws
A JSON Web Signature as returned by jose_sign()
.
Returns 0
(zero) on failure, and an array
Array | |
| The JOSE header. |
| The signed message. |
pkcs_verify()
, RFC 7515 section 3.5
string(7bit)
|zero
jose_sign(string(8bit)
message
, .Hash
|void
h
, mapping
(string(7bit)
:string(7bit)
|int
)|void
headers
)
Signs the message
with a JOSE JWS ECDSA signature using hash
algorithm h
.
message
Message to sign.
h
Hash algorithm to use.
Returns the signature on success, and 0
(zero)
on failure.
pkcs_verify()
, salt_size()
, RFC 7515
string(7bit)
|zero
jwa(.Hash
hash
)
Get the JWS algorithm identifier for a hash.
Returns 0
(zero) on failure.
mapping
(string(7bit)
:string(7bit)
)|zero
jwk(bool
|void
private_key
)
Generate a JWK-style mapping of the object.
private_key
If true, include the private key in the result.
Returns a JWK-style mapping on success, and 0
(zero)
on failure.
create()
, Web.encode_jwk()
, RFC 7517 section 4, RFC 7518 section 6.2
int(0..)
key_size()
Return the size of the private key in bits.
Sequence
pkcs_algorithm_identifier()
Returns the AlgorithmIdentifier as defined in RFC 5480 section 2.1.1 including the ECDSA parameters.
Sequence
pkcs_public_key()
Creates a SubjectPublicKeyInfo ASN.1 sequence for the object. See RFC 5280 section 4.1.2.7 and RFC 5480 section 2.2.
string(8bit)
pkcs_sign(string(8bit)
message
, .Hash
h
)
Signs the message
with a PKCS-1 signature using hash algorithm
h
.
Sequence
|zero
pkcs_signature_algorithm_id(.Hash
hash
)
Returns the PKCS-1 algorithm identifier for ECDSA and the provided hash algorithm. Only SHA-1 and SHA-2 based hashes are supported currently.
bool
pkcs_verify(string(8bit)
message
, .Hash
h
, string(8bit)
sign
)
Verify PKCS-1 signature sign
of message message
using hash
algorithm h
.
bool
public_key_equal(this_program
ecdsa
)
Compares the public key in this object with that in the provided ECDSA object.
this_program
set_private_key(Gmp.mpz
|int
k
)
Set the private key.
Throws errors if the key isn't valid for the curve.
variant
this_program
set_private_key(string(8bit)
k
)
Set the private key.
Throws errors if the key isn't valid for the curve.
this_program
set_public_key(Gmp.mpz
|int
x
, Gmp.mpz
|int
y
)
Change to the selected point on the curve as public key.
Throws errors if the point isn't on the curve.
variant
this_program
set_public_key(string(8bit)
key
)
Change to the selected point on the curve as public key.
key
The public key encoded according to ANSI x9.62 4.3.6.
Throws errors if the point isn't on the curve.
this_program
set_random(function
(int
:string(8bit)
) r
)
Set the random function, used to generate keys and parameters,
to the function r
.
int
size()
Return the curve size in bits.
The definition of the elliptic curve X25519.
Curve
, Curve448
inherit Nettle.Curve25519 : Curve25519
Sequence
pkcs_algorithm_identifier()
Returns the AlgorithmIdentifier for the curve as defined in RFC 8410 section 3.
Identifier
pkcs_eddsa_id()
Returns the EdDSA AlgorithmIdentifier as defined in RFC 8410 section 3.
Identifier
pkcs_named_curve_id()
Returns the PKCS-1 elliptic curve identifier for the curve. cf RFC 8410 section 3.
Edwards Curve Digital Signing Algorithm
inherit Curve25519::EdDSA : EdDSA
bool
equal(Crypto.ECC.Curve25519.EdDSA from, mixed
other
)
Compares the keys of this ECDSA object with something other.
this_program
generate_key()
Generate a new set of private and public keys on the current curve.
_Curve25519
get_curve()
Return the curve.
Point
get_point()
Get the public key curve point.
string(8bit)
get_public_key()
Get the ANSI x9.62 4.3.6 encoded uncompressed public key.
array
(mapping
(string(7bit)
:string(7bit)
|int
)|string(8bit)
)|zero
jose_decode(string(7bit)
jws
)
Verify and decode a JOSE JWS EdDSA signed value.
jws
A JSON Web Signature as returned by jose_sign()
.
Returns 0
(zero) on failure, and an array
Array | |
| The JOSE header. |
| The signed message. |
pkcs_verify()
, RFC 7515 section 3.5
string(7bit)
|zero
jose_sign(string(8bit)
message
, .Hash
|void
h
, mapping
(string(7bit)
:string(7bit)
|int
)|void
headers
)
Signs the message
with a JOSE JWS EdDSA signature.
message
Message to sign.
h
Hash algorithm to use; ignored for Ed25519.
Returns the signature on success, and 0
(zero)
on failure.
pkcs_verify()
, salt_size()
, RFC 7515
string(7bit)
jwa(.Hash
|void
hash
)
Get the JWS algorithm identifier for a hash.
hash
Hash algorithm; ignored for Ed25519.
Returns 0
(zero) on failure.
mapping
(string(7bit)
:string(7bit)
)|zero
jwk(bool
|void
private_key
)
Generate a JWK-style mapping of the object.
private_key
If true, include the private key in the result.
Returns a JWK-style mapping on success, and 0
(zero)
on failure.
create()
, Web.encode_jwk()
, RFC 8037
int(0..)
key_size()
Return the size of the private key in bits.
Sequence
pkcs_algorithm_identifier()
Returns the AlgorithmIdentifier as defined in RFC 5480 section 2.1.1 including the EdDSA parameters.
Identifier
pkcs_named_curve_id()
Returns the EdDSA identifier for the curve.
Sequence
pkcs_public_key()
Creates a SubjectPublicKeyInfo ASN.1 sequence for the object. See RFC 5280 section 4.1.2.7.
string(8bit)
pkcs_sign(string(8bit)
message
, .Hash
|void
h
)
Signs the message
with a PKCS-1 signature using hash algorithm
h
.
h
Hash algorithm; ignored for Curve25519
.
Sequence
pkcs_signature_algorithm_id(.Hash
|void
hash
)
Returns the PKCS-1 algorithm identifier for EdDSA and the provided hash algorithm.
hash
Hash algorithm; ignored for Curve25519
.
bool
pkcs_verify(string(8bit)
message
, .Hash
|void
h
, string(8bit)
sign
)
Verify PKCS-1 signature sign
of message message
using hash
algorithm h
.
h
Hash algorithm; ignored for Ed25519.
bool
public_key_equal(this_program
eddsa
)
Compares the public key in this object with that in the provided ECDSA object.
this_program
set_private_key(string(8bit)
k
)
Set the private key.
Throws errors if the key isn't valid for the curve.
this_program
set_public_key(string(8bit)
key
)
variant
this_program
set_public_key(Point
p
)
this_program
set_random(function
(int
:string(8bit)
) r
)
Set the random function, used to generate keys and parameters,
to the function r
.
int
size()
Return the curve size in bits.
inherit Curve : Curve
inherit Curve : Curve
inherit Curve : Curve
inherit Curve : Curve
inherit Curve : Curve
inherit Curve : Curve
inherit Curve : Curve
The GOST94 or GOST R 34.11-94 hash algorithm is a Soviet-era algorithm used in Russian government standards, defined in RFC 4357.
inherit Nettle.GOST94 : GOST94
The GOST94 or GOST R 34.11-94 hash algorithm is a Soviet-era algorithm used in Russian government standards. This is the "CryptoPro" variant.
GOST94
inherit Nettle.GOST94CP : GOST94CP
The IDEA(tm) block cipher is covered by patents held by ETH and a Swiss company called Ascom-Tech AG. The Swiss patent number is PCT/CH91/00117, the European patent number is EP 0 482 154 B1, and the U.S. patent number is US005214703. IDEA(tm) is a trademark of Ascom-Tech AG. There is no license fee required for noncommercial use.
inherit Nettle.IDEA : IDEA
Quote from Koremutake home page http://shorl.com/koremutake:
In an attempt to temporarily solve the fact that human beings seem to be inable to remember important things (such as their names, car keys and seemingly random numbers with fourteen digits in 'em), we invented Koremutake.
It is, in plain language, a way to express any large number as a sequence of syllables. The general idea is that word-sounding pieces of information are a lot easier to remember than a sequence of digits.
Note this encoding is NOT suitable for encoding numeric quantities where initial zeroes are significant (ie it is NOT suitable for eg PIN-numbers).
This module implements an API that is similar to (but NOT compatible
with) the generic Crypto.Cipher
API.
int(0..)
decrypt(string(7bit)
c
)
Decode a koremutake string into an integer.
Returns an integer. This is not compatible with the
Crypto.Cipher
API.
string(7bit)
encrypt(int(0..)
m
)
Encode an integer as a koremutake string.
Encrypts an integer. This is not compatible with the
Crypto.Cipher
API.
int(0..)
|string(7bit)
crypt(int(0..)
|string(7bit)
x
)
Encrypts or returns an integer. This is not compatible with the
Crypto.Cipher
API.
MD2 is a message digest function constructed by Burton Kaliski, and is described in RFC 1319. It outputs message digests of 128 bits, or 16 octets.
inherit Nettle.MD2 : MD2
MD4 is a message digest function constructed by Ronald Rivest, and is described in RFC 1320. It outputs message digests of 128 bits, or 16 octets.
inherit Nettle.MD4 : MD4
MD5 is a message digest function constructed by Ronald Rivest, and is described in RFC 1321. It outputs message digests of 128 bits, or 16 octets.
inherit Nettle.MD5 : MD5
string(7bit)
crypt_hash(string(8bit)
password
, string(7bit)
salt
, int(0..)
|void
rounds
)
This is a convenience alias for Nettle.crypt_md5()
,
that uses the same API as the other hashes.
The rounds
parameter is currently ignored.
For forward compatibility, either leave out,
or specify as 1000
.
Nettle.Hash()->crypt_hash()
, crypt_md5()
Class representing an HCRYPTPROV handle.
Crypto.NT.CryptContext Crypto.NT.CryptContext(
string(8bit)
name
, string(8bit)
csp
, int
type
, int
flags
)
name
Key container name. When flags is set to CRYPT_VERIFYCONTEXT
the name must be 0
.
csp
The name of the Crypto Service Provider to use. If set to
0
the user default CSP will be used.
string(8bit)
read(int
size
, string(8bit)
|void
init
)
Retreive some random data. Calls CryptGenRandom in the NT API.
NT Lan Manager authentication protocol primitives.
These functions use obsolete crypto primitives in weak and questionable ways, and should be avoided if possible. They are only intended to be used for interop with old code.
[MS-NLMP]:http://download.microsoft.com/download/9/5/e/95ef66af-9026-4bb0-a41d-a4f81802d92c/[ms-nlmp].pdf
string(8bit)
LMOWFv1(string
Passwd
, string
User
, string
UserDom
)
Lan-Manager One-Way Function version 1.
This function is also known as LM hash.
string(8bit)
LMOWFv2(string
Passwd
, string
User
, string
UserDom
)
Lan-Manager One-Way Function version 2.
This function is identical to NTOWFv2()
.
string(8bit)
NTOWFv1(string
Passwd
, string
User
, string
UserDom
)
NT One-Way Function version 1.
string(8bit)
NTOWFv2(string
Passwd
, string
User
, string
UserDom
)
NT One-Way Function version 2.
string(8bit)
SBKv1(string
Passwd
, string
User
, string
UserDom
)
Session Base Key for NTLMv1.
The plaintext algorithm.
This modules implements several of the crypto APIs, but without any crypto. It is intended to be used for testing of higher level algorithms.
inherit .AE : AE
Implements the empty AE algorithm.
inherit .MAC : MAC
Implements the empty MAC algorithm.
protected
constantstring
Crypto.None.mac_jwa_id
Implements the "none" JWS algorithm.
PGP stuff. See RFC 4880.
mapping
(string
:string
|mapping
|array
) decode(string
s
)
Decodes PGP data.
mapping
(string
:mixed
) decode_radix64(string
data
)
Decode ASCII armour.
string
encode_radix64(string
data
, string
type
, mapping
(string
:string
)|void
extra
)
Encode PGP data with ASCII armour.
int
verify_signature(string
text
, string
sig
, string
pubkey
)
Verify text
against signature sig
with the public key
pubkey
.
RC4 is a stream cipher, sometimes refered to as Arcfour, and while very fast isn't considered secure anymore.
The key setup of RC4 is quite weak, so you should never use keys with structure, such as ordinary passwords. If you have keys that don't look like random bit strings, and you want to use RC4, always hash the key before feeding it to RC4.
The first few thousand bits have a slight bias, so it is not uncommon for applications to encrypt a few kilobytes of dummy data before actual encryption.
inherit Nettle.ARCFOUR : pre
RIPEMD160 is a hash function designed by Hans Dobbertin, Antoon Bosselaers, and Bart Preneel, as a strengthened version of RIPEMD (which, like MD4 and MD5, fails the collision-resistance requirement). It produces message digests of 160 bits, or 20 octets.
inherit Nettle.RIPEMD160 : RIPEMD160
inherit Crypto.Sign : Sign
protected
State
`()(mapping
(string(8bit)
:Gmp.mpz
|int
|string(7bit)
)|void
params
)
Calling `() will return a State
object with the given params
.
State()
string(8bit)
name()
Returns the string "RSA"
.
inherit Sign::State : State
bool
equal(Crypto.RSA.LowState from, mixed
other
)
Compares the keys of this RSA object with something other.
Crypto.RSA.LowState Crypto.RSA.LowState(
mapping
(string(8bit)
:Gmp.mpz
|int
|string(7bit)
)|void
params
)
Can be initialized with a mapping with the elements n, e, d, p and q.
The mapping can either contain integer values, or be an RFC 7517
JWK-style mapping with kty set to "RSA"
and contain
MIME.encode_base64url()
-encoded values.
jwk()
this_program
generate_key(int(89..)
bits
, int(1..)
|Gmp.mpz
|void
e
)
Generate a valid RSA key pair with the size bits
using the
random function set with set_random()
. The public exponent e
will be used, which defaults to 65537. Keys must be at least 89
bits.
Gmp.mpz
|zero
get_d()
Returns the RSA private exponent (d), if known.
Gmp.mpz
|zero
get_e()
Returns the RSA public exponent (e).
Gmp.mpz
|zero
get_n()
Returns the RSA modulo (n).
Gmp.mpz
|zero
get_p()
Returns the first RSA prime (p), if known.
Gmp.mpz
|zero
get_q()
Returns the second RSA prime (q), if known.
string(7bit)
jwa(.Hash
hash
)
Get the JWS algorithm identifier for a hash.
Returns 0
(zero) on failure.
mapping
(string(7bit)
:string(7bit)
)|zero
jwk(bool
|void
private_key
)
Generate a JWK-style mapping of the object.
private_key
If true, include the private key in the result.
Note that if the private key isn't known, the function
will fail (and return 0
).
Returns a JWK-style mapping on success, and 0
(zero)
on failure.
create()
, Web.encode_jwk()
, RFC 7517 section 4, RFC 7518 section 6.3
int(0..)
key_size()
Returns the size of the key in terms of number of bits.
string(8bit)
name()
Returns the string "RSA"
.
bool
public_key_equal(this_program
rsa
)
Compares the public key of this RSA object with another RSA object.
this_program
set_decrypt_key(array
(Gmp.mpz
) key
)
Sets the public key to key
and the mod to decryption.
set_encrypt_key
, crypt
this_program
set_encrypt_key(array
(Gmp.mpz
) key
)
Sets the public key to key
and the mode to encryption.
set_decrypt_key
, crypt
this_program
set_private_key(Gmp.mpz
|int
priv
, array
(Gmp.mpz
|int
)|void
extra
)
Sets the private key.
priv
The private RSA exponent, often called d.
extra
Array | |
| The first prime, often called p. |
| The second prime, often called q. |
this_program
set_public_key(Gmp.mpz
|int
modulo
, Gmp.mpz
|int
pub
)
Sets the public key.
modulo
The RSA modulo, often called n. This value needs to be >=12.
pub
The public RSA exponent, often called e.
this_program
set_random(function
(int(0..)
:string(8bit)
) r
)
Sets the random function, used to generate keys and parameters, to
the function r
. Default is random_string
.
Implementation of RSAES-OAEP (Optimal Asymmetric Encryption Padding).
inherit LowState : LowState
this_program
Crypto.RSA.OAEPState.OAEP
Get the OAEP encryption state.
Read only
local
int
block_size()
Returns the crypto block size, in bytes, or zero if not yet set.
local
string(8bit)
crypt(string(8bit)
s
, string(8bit)
|void
label
)
Encrypt or decrypt depending on set mode.
set_encrypt_key
, set_decrypt_key
PKCS#1 1.5 encryption (RFC 3447 section 7.2) and signatures (RFC 3447 section 8.2).
PSSState
inherit PSSState : PSSState
this_program
Crypto.RSA.PKCS1_5State.PKCS1_5
Get the PKCS#1 1.5 state.
Read only
int
block_size()
Returns the crypto block size, in bytes, or zero if not yet set.
string(8bit)
|zero
crypt(string(8bit)
s
)
Encrypt or decrypt depending on set mode.
set_encrypt_key
, set_decrypt_key
string(8bit)
|zero
decrypt(string(8bit)
s
)
Decrypt a message encrypted with encrypt
.
string(8bit)
encrypt(string(8bit)
s
, function
(int
:string(8bit)
)|void
r
)
Pads the message s
with rsa_pad
type 2, signs it and returns
the signature as a byte string.
r
Optional random function to be passed down to rsa_pad
.
array
(mapping
(string(7bit)
:string(7bit)
|int
)|string(8bit)
)|zero
jose_decode(string(7bit)
jws
)
Verify and decode a JOSE JWS RSASSA-PKCS-v1.5 signed value.
jws
A JSON Web Signature as returned by jose_sign()
.
Returns 0
(zero) on failure, and an array
Array | |
| The JOSE header. |
| The signed message. |
on success.
pkcs_verify()
, RFC 7515 section 3.5
string(7bit)
|zero
jose_sign(string(8bit)
message
, mapping
(string(7bit)
:string(7bit)
|int
)|void
headers
, .Hash
|void
h
)
Signs the message
with a JOSE JWS RSASSA-PKCS-v1.5 signature using hash
algorithm h
.
message
Message to sign.
headers
JOSE headers to use. Typically a mapping with a single element
"typ"
.
h
Hash algorithm to use. Currently defaults to SHA256
.
Returns the signature on success, and 0
(zero)
on failure (typically that the hash + salt combo is too
large for the RSA modulo).
pkcs_verify()
, salt_size()
, RFC 7515
string(7bit)
|zero
jwa(.Hash
hash
)
Get the JWS algorithm identifier for a hash.
Returns 0
(zero) on failure.
string(8bit)
name()
Returns the string "RSA"
.
Sequence
pkcs_public_key()
Calls Standards.PKCS.RSA.build_public_key
with this object as
argument.
string(8bit)
pkcs_sign(string(8bit)
message
, .Hash
h
)
Signs the message
with a PKCS-1 signature using hash
algorithm h
. This is equivalent to
I2OSP(RSASP1(OS2IP(RSAES-PKCS1-V1_5-ENCODE(message)))) in PKCS#1
v2.2.
Sequence
pkcs_signature_algorithm_id(.Hash
hash
)
Calls Standards.PKCS.RSA.signature_algorithm_id
with the
provided hash
.
bool
pkcs_verify(string(8bit)
message
, .Hash
h
, string(8bit)
sign
)
Verify PKCS-1 signature sign
of message message
using hash
algorithm h
.
Gmp.mpz
raw_sign(string(8bit)
digest
)
Pads the digest
with rsa_pad
type 1 and signs it. This is
equivalent to RSASP1(OS2IP(RSAES-PKCS1-V1_5-ENCODE(message))) in
PKCS#1 v2.2.
bool
raw_verify(string(8bit)
digest
, Gmp.mpz
s
)
Verifies the digest
against the signature s
, assuming pad
type 1.
rsa_pad
, raw_sign
Gmp.mpz
rsa_pad(string(8bit)
message
, int(1..2)
type
, function
(int(0..)
:string(8bit)
)|void
random
)
Pads the message
to the current block size with method
type
and returns the result as an integer. This is equivalent
to OS2IP(RSAES-PKCS1-V1_5-ENCODE(message)) in PKCS#1 v2.2.
type
| The message is padded with |
| The message is padded with random data, using the |
string(8bit)
|zero
rsa_unpad(Gmp.mpz
block
, int
type
)
Reverse the effect of rsa_pad
.
RSA PSS signatures (RFC 3447 section 8.1).
PKCS1_5State
inherit OAEPState : OAEPState
this_program
Crypto.RSA.PSSState.PSS
Get the PSS signature state.
Read only
local
array
(mapping
(string(7bit)
:string(7bit)
|int
)|string(8bit)
)|zero
jose_decode(string(7bit)
jws
)
Verify and decode a JOSE JWS RSASSA-PSS signed value.
jws
A JSON Web Signature as returned by jose_sign()
.
Returns 0
(zero) on failure, and an array
Array | |
| The JOSE header. |
| The signed message. |
pkcs_verify()
, RFC 7515 section 3.5
local
string(7bit)
|zero
jose_sign(string(8bit)
message
, mapping
(string(7bit)
:string(7bit)
|int
)|void
headers
, .Hash
|void
h
)
Signs the message
with a JOSE JWS RSASSA-PSS signature using hash
algorithm h
.
message
Message to sign.
headers
JOSE headers to use. Typically a mapping with a single element
"typ"
.
h
Hash algorithm to use. Currently defaults to SHA256
.
Returns the signature on success, and 0
(zero)
on failure (typically that the hash + salt combo is too
large for the RSA modulo).
pkcs_sign()
, salt_size()
, RFC 7515 section 3.5
local
string(7bit)
|zero
jwa(.Hash
hash
)
Get the JWS algorithm identifier for a hash.
Returns 0
(zero) on failure.
local
string(8bit)
pkcs_sign(string(8bit)
message
, .Hash
h
, string(8bit)
|int(0..)
|void
salt
)
Signs the message
with a RSASSA-PSS signature using hash
algorithm h
.
message
Message to sign.
h
Hash algorithm to use.
salt
Either of
| Use a |
| Use a |
| Use this specific salt. |
Returns the signature on success, and 0
(zero)
on failure (typically that the hash + salt combo is too
large for the RSA modulo).
pkcs_verify()
, salt_size()
, RFC 3447 section 8.1.1
local
Sequence
pkcs_signature_algorithm_id(.Hash
hash
, int(0..)
|void
saltlen
)
Calls Standards.PKCS.RSA.pss_signature_algorithm_id
with the
provided hash
and saltlen
.
hash
Hash algorithm for the signature.
saltlen
Length of the salt for the signature. Defaults to the
value returned by salt_size()
.
local
bool
pkcs_verify(string(8bit)
message
, .Hash
h
, string(8bit)
sign
, int(0..)
|void
saltlen
)
Verify RSASSA-PSS signature sign
of message message
using hash
algorithm h
.
inherit PKCS1_5State : PKCS1_5State
This module contains a pseudo random number generator (PRNG) designed to give you the best possible random number generation. The current design is based on the Fortuna PRNG, but uses the system random source as input.
inherit Random.Fast : Fast
void
add_entropy(string(8bit)
data
)
Inject additional entropy into the random generator. One possible
use is to persist random data between executions of an
application. The internal state is approximately 256 bits, so
storing 32 bytes from random_string()
at shutdown and injecting
them through add_entropy()
again at startup should carry over
the entropy. Note that this doesn't affect the independent
initialization that happens in the generator at startup, so the
output sequence will be different than if the application had
continued uninterrupted.
data
The random string.
string(8bit)
random_string(int(0..)
len
)
Returns a string of length len
with random content. The content
is generated by a Fortuna random generator that is updated with
output from /dev/urandom on UNIX and CryptGenRandom on NT.
The SALSA20 stream cipher.
inherit Nettle.SALSA20 : SALSA20
The SALSA20
stream cipher reduced to just 12 rounds.
inherit Nettle.SALSA20R12 : SALSA20R12
SHA1 is a hash function specified by NIST (The U.S. National Institute for Standards and Technology). It outputs hash values of 160 bits, or 20 octets.
inherit Nettle.SHA1 : SHA1
inherit ::this_program : this_program
string(7bit)
crypt_hash(string(8bit)
password
, string(7bit)
salt
, int(0..)
rounds
)
crypt_sha1() from NetBSD.
SHA224 is another hash function specified by NIST, intended as a
replacement for SHA1
, generating larger digests. It outputs hash
values of 224 bits, or 28 octets.
inherit Nettle.SHA224 : SHA224
SHA256 is another hash function specified by NIST, intended as a
replacement for SHA1
, generating larger digests. It outputs hash
values of 256 bits, or 32 octets.
inherit Nettle.SHA256 : SHA256
SHA384 is another hash function specified by NIST, intended as a
replacement for SHA1
, generating larger digests. It outputs hash
values of 384 bits, or 48 octets.
inherit Nettle.SHA384 : SHA384
SHA-3-224 is another hash function specified by NIST, intended as a replacement for SHA-2. It outputs hash values of 224 bits, or 28 octets.
inherit Nettle.SHA3_224 : SHA3_224
SHA-3-256 is another hash function specified by NIST, intended as a replacement for SHA-2. It outputs hash values of 256 bits, or 32 octets.
inherit Nettle.SHA3_256 : SHA3_256
SHA-3-386 is another hash function specified by NIST, intended as a replacement for SHA-2. It outputs hash values of 256 bits, or 48 octets.
inherit Nettle.SHA3_384 : SHA3_384
SHA-3-512 is another hash function specified by NIST, intended as a replacement for SHA-2. It outputs hash values of 512 bits, or 64 octets.
inherit Nettle.SHA3_512 : SHA3_512
SHA512 is another hash function specified by NIST, intended as a
replacement for SHA1
, generating larger digests. It outputs hash
values of 512 bits, or 64 octets.
inherit Nettle.SHA512 : SHA512
SHA512/224 is another hash function specified by NIST. It is
similar to SHA512
except it uses a different initialization and
the output is truncated to 224 bits, or 28 octets.
inherit Nettle.SHA512_224 : SHA512_224
SHA512/256 is another hash function specified by NIST. It is
similar to SHA512
except it uses a different initialization and
the output is truncated to 256 bits, or 32 octets.
inherit Nettle.SHA512_256 : SHA512_256
SHAKE-256 is an extendable output function (XOF) based on SHA3_256
.
It can provide an output digest of any length.
SHA3_256.shake()
inherit Crypto.SHA3_256 : SHA3_256
SM3 is a cryptographic hash function standard adopted by the government of the People's Republic of China. It outputs hash values of 256 bits, or 32 octets.
inherit Nettle.SM3 : SM3
The SM4 block cipher.
inherit Nettle.SM4 : SM4
The STREEBOG256 algorithm is a member of the Streebog (GOST R 34.11-2012) family of hash algorithms, and is used in Russian government standards.
STREEBOG512
inherit Nettle.STREEBOG256 : STREEBOG256
The STREEBOG512 algorithm is a member of the Streebog (GOST R 34.11-2012) family of hash algorithms, and is used in Russian government standards.
STREEBOG256
inherit Nettle.STREEBOG512 : STREEBOG512
SERPENT is one of the AES finalists, designed by Ross Anderson,
Eli Biham and Lars Knudsen. Thus, the interface and properties are
similar to AES
'. One peculiarity is that it is quite pointless to
use it with anything but the maximum key size, smaller keys are
just padded to larger ones.
inherit Nettle.SERPENT : SERPENT
Another AES
finalist, this one designed by Bruce Schneier and
others.
inherit Nettle.Twofish : Twofish
Low level crypto functions used by the Crypto
module. Unless
you are doing something very special, you would want to use the
Crypto module instead.
string(7bit)
bcrypt_hash(string(8bit)
password
, string(7bit)
scheme
, string(8bit)
|void
salt
, int
|void
log2rounds
)
Low level implementation of the bcrypt password-hashing algorithm.
password
The cleartext password. Only accepts 8-bit strings. Typically passwords are encoded in UTF-8 NFC, but some platforms may have other conventions.
scheme
Specifies the scheme to be used to generate the hash.
The settings either cleanly specify the scheme of either "2a"
,
"2b"
, "2x"
or "2y"
, or they contain the (or part
of the prefix of) normal hashed password string, so an existing hashed
password string may be passed unmodified.
When generating a new hash from scratch, the following minimum needs to be
specified, e.g. "$2y$10$1b2lPgo4XumibnJGN3r3sO"
. In this
"$"
is the separator, "2y"
specifies the used
hash-algorithm, "10"
specifies 2^10
encryption rounds
and "1b2lPgo4XumibnJGN3r3sO"
is the salt (16 bytes, base64 encoded).
The minimal value for settings would be "$2y$"
.
salt
The salt can be supplied as part of settings
, or separately
as a 16-byte binary string.
log2rounds
The log2 number of encryption rounds. If unspecified it is taken
from the settings string, and if not specified there it defaults to
10
which equals 1024 encryption rounds.
Returns the (according to the specified algorithm, encryption rounds, and salt) hashed and encoded version of the supplied password. Throws an error on invalid input.
You should normally use Crypto.Password
instead.
Requires Nettle 2.7 or later.
Crypto.Password
, Crypto.BLOWFISH
int
bcrypt_verify(string(8bit)
password
, string(7bit)
hashedpassword
)
Low level implementation of the bcrypt password-verifying algorithm.
password
The cleartext password. Only accepts 8-bit strings.
hashedpassword
This is the full hashed password string.
Returns 1
if the cleartext password matches the hashed password
and zero otherwise.
You should normally use Crypto.Password
instead.
Requires Nettle 2.7 or later.
Crypto.Password
, Crypto.BLOWFISH
int(0..)
crc32c(string(8bit)
data
, void
|int(0..)
seed
)
Implements the Castagnoli CRC, CRC32C. Hardware optimized on Intel CPUs with SSE 4.2.
seed
Can be fed with the result of the previous invocation to chain on new data. Defaults to zero on virgin runs.
string(7bit)
crypt_md5(string(8bit)
password
, string(8bit)
salt
, void
|string(8bit)
magic
)
Does the crypt_md5 abrakadabra (MD5 + snakeoil). It is assumed
that salt
does not contain "$".
The password
memory will be cleared before released.
array
(Gmp.mpz
) dsa_generate_keypair(int
p_bits
, int
q_bits
, function
(int(0..)
:string(8bit)
) rnd
)
Generates a DSA key pair with p_bits
number of bits (sometimes
referred to as L) for p, and q_bits
number of bits (sometimes
referred to as N) for q, using the random function rnd
.
Valid combinations as per FIPS 186-3 are
p_bits q_bits 1024 160 2048 224 (rejected by some versions of Hogweed) 2048 256 3072 256
Array | |
| The value p, the modulo. |
| The value q, the group order. |
| The value g, the generator. |
| The value y, the public value. |
| The value x, the private value. |
array
(Gmp.mpz
) rsa_generate_keypair(int
bits
, int
e
, function
(int(0..)
:string(8bit)
) rnd
)
Generates an RSA key pair with a bits
sized modulus (n), using
the provided value for e
and random function rnd
.
Array | |
| The value n, the modulo. |
| The value d, the private exponent. |
| The value p, a prime. |
| The value q, a prime. |
int(0..)
rsa_unpad(string(8bit)
data
, int(1..2)
type
)
Unpads a message that has been padded according to
RSAES-PKCS1-V1_5-ENCODE(message) in PKCS#1 v2.2, but without the
null byte prefix. The padding method used on the original message
must be provided in the type
parameter. All content dependent
processing is done in constant time for the same padding type and
data
length.
Returns the position in the string where the first non-padding character is, or 0.
string
version()
Returns the version of the Nettle library, e.g. "3.1". 0 is returned when runtime version is unknown.
Represents information about an Authenticated Encryption with Associated Data (AEAD) algorithm, such as name, key size, digest size, and block size.
inherit __builtin.Nettle.AEAD : AEAD
int(0..)
block_size()
The block size of the AEAD algorithm.
Note that AEAD algorithms often support automatic padding, so that the last block does not need to be complete.
int(0..)
digest_size()
Returns the size of a MAC digest.
int(0..)
iv_size()
Returns the size of the iv/nonce of the AEAD algorithm (if any).
Returns 0
(zero) if there is no configurable iv/nonce.
int(0..)
key_size()
The recommended key size for the cipher.
string(8bit)
name()
A human readable name for the algorithm.
Base class for AEAD contexts.
inherit AEAD::State : State
int(0..)
block_size()
The block size for this cipher.
The default implementation just calls Cipher::block_size()
in the parent.
string(8bit)
crypt(string(8bit)
data
)
Encrypts or decrypts data, using the current key. Neither the
input nor output data is automatically memory scrubbed,
unless String.secure
has been called on them.
data
Data must be an integral number of blocks, except for the last segment.
The encrypted or decrypted data.
string(8bit)
digest(int
|void
length
)
Generates a digest, and resets the AEAD contents.
Also updates the iv/nonce (if any).
length
If the length argument is provided, the digest is truncated to the given length.
The digest.
int(0..)
digest_size()
Returns the size of a MAC digest.
int(0..)
iv_size()
Returns the size of the iv/nonce of the AEAD algorithm (if any).
Returns 0
(zero) if there is no configurable iv/nonce.
int(0..)
key_size()
The actual key size for this cipher.
string(8bit)
make_key()
Generate a key by calling random_string
and initialize this
object for encryption with that key.
The generated key. The key memory will be cleared before released.
set_encrypt_key
string(8bit)
name()
A human readable name for the algorithm.
The default implementation just calls Cipher::name()
in the parent.
State
set_decrypt_key(string(8bit)
key
)
Initializes the object for decryption. The key
memory will be
cleared before released.
set_encrypt_key
, crypt
State
set_encrypt_key(string(8bit)
key
)
Initializes the object for encryption. The key
memory will be
cleared before released.
set_decrypt_key
, crypt
State
set_iv(string(8bit)
iv
)
Set the iv/nonce (if supported) for the AEAD.
Returns this
in order to simplify chaining
of function calls.
State
update(string(8bit)
data
)
Add some more associated data.
All associated data typically needs to be added before any data to actually encrypt.
Returns this
in order to simplify chaining
of function calls.
Implementation of the AES cipher.
inherit BlockCipher16 : BlockCipher16
State for AES encyption.
inherit BlockCipher16::State : State
Implementation of the AES128 cipher.
inherit BlockCipher16 : BlockCipher16
State for AES128 encyption.
inherit BlockCipher16::State : State
Minimal implementation of NIST SP800-90Ar1 pseudo random number generator CTR_DRBG using AES-128. No personalization, nounces or additional data are supported.
Random.AES128_CTR_DRBG
int(1..281474976710656)
Nettle.AES128_CTR_DRBG.reseed_interval
The number of times random_string
can be called before a
reseeding is forced. The number needs to be in the range of
1..1<<48.
entropy_underflow
int(1..281474976710656)
Nettle.AES128_CTR_DRBG.reseed_interval
The number of times random_string
can be called before a
reseeding is forced. The number needs to be in the range of
1..1<<48.
entropy_underflow
void
entropy_underflow()
Called when random_string
has been called more than
reseed_interval
times.
string(8bit)
random_string(int(0..)
len
)
Generates len
amount of pseudo random data. Does not allow
for additional input data in the call.
void
reseed(string(8bit)
data
)
Updated the internal key with the provided additional entropy.
Implementation of the AES192 cipher.
inherit BlockCipher16 : BlockCipher16
State for AES192 encyption.
inherit BlockCipher16::State : State
Implementation of the AES256 cipher.
inherit BlockCipher16 : BlockCipher16
State for AES256 encyption.
inherit BlockCipher16::State : State
Implementation of the ARCFOUR cipher.
inherit Cipher : Cipher
State for ARCFOUR encyption.
inherit Cipher::State : State
Implementation of the ARCTWO cipher.
inherit BlockCipher : BlockCipher
State for PIKE_NAME encyption.
inherit Cipher::State : State
State
set_decrypt_key(string(8bit)
key
, void
|int
ekb
)
Initializes the object for decryption. The key
memory will be
cleared before released.
ekb
The effective number of bits in the key.
| Derive from the key size (ie |
| Convenience alias for max (ie |
| Reduce the effective key size to the specified number of bits. |
set_encrypt_key
, crypt
State
set_encrypt_key(string(8bit)
key
, int
|void
ekb
)
Initializes the object for encryption. The key
memory will be
cleared before released.
ekb
The effective number of bits in the key.
| Derive from the key size (ie |
| Convenience alias for max (ie |
| Reduce the effective key size to the specified number of bits. |
set_decrypt_key
, crypt
Implementation of the BLOWFISH cipher.
inherit BlockCipher : BlockCipher
State for BLOWFISH encyption.
inherit BlockCipher::State : State
Base class for all block ciphers.
Extends the BufferedCipher
class with various operating modes.
inherit __builtin.Nettle.BlockCipher : BlockCipher
inherit BufferedCipher : BufferedCipher
Implementation of the Accumulated Block Chaining mode (ABC).
This is a mode of operation similar to IGE
, but
where the plaintext is mixed with both initialization
vectors. It was suggested as a mode of operation for
AES
by Lars R. Knudsen.
CBC
, GCM
, CFB
, IGE
inherit BufferedCipher : BufferedCipher
inherit Cipher::State : State
int(1..)
block_size()
Returns the block size of the encapsulated cipher.
Nettle.BlockCipher.ABC.State Nettle.BlockCipher.ABC.State()
Initialize the ABC state with the Cipher::State
object
returned by substate_factory()
. This is usually
the State for the cipher implemented in the parent module.
string(8bit)
crypt(string(8bit)
data
)
Encrypt/decrypt data
and return the result. data
must
be an integral number of blocks.
Neither the input or output data is not automatically memory
scrubbed, unless String.secure
has been called on the data.
int(1..)
iv_size()
Returns the size for the initialization vector
int(1..)
key_size()
Returns the key size of the encapsulated cipher.
string(8bit)
name()
Returns the string "ABC(x)"
where x is the
encapsulated algorithm.
this_program
set_decrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for decrypting with the given
key
. The key
memory will be cleared before released.
this_program
set_encrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for encrypting with the given
key
. The key
memory will be cleared before released.
this_program
set_iv(string(8bit)
iv
)
Set the initialization vector to iv
. The iv
memory will be
cleared before released.
ABC semantically has two initialization vectors of size
block_size()
; x0 (previous plaintext) and y0
(previous ciphertext). They are here concatenated to a single
initialization vector of double the block size.
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
Implementation of the Cipher Block Chaining mode (CBC).
Works as a wrapper for the cipher implemented by overloading
the parent class (Cipher
).
Crypto.CBC
, GCM
inherit BufferedCipher : BufferedCipher
inherit Cipher::State : State
int(1..)
block_size()
Returns the block size of the encapsulated cipher.
Nettle.BlockCipher.CBC.State Nettle.BlockCipher.CBC.State()
Initialize the CBC state with the Cipher::State
object
returned by substate_factory()
. This is usually
the State for the cipher implemented in the parent module.
string(8bit)
crypt(string(8bit)
data
)
Encrypt/decrypt data
and return the result. data
must
be an integral number of blocks.
Neither the input or output data is not automatically memory
scrubbed, unless String.secure
has been called on the data.
int(1..)
iv_size()
Returns the size for the initialization vector
int(1..)
key_size()
Returns the key size of the encapsulated cipher.
string(8bit)
name()
Returns the string "CBC(x)"
where x is the
encapsulated algorithm.
this_program
set_decrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for decrypting with the given
key
. The key
memory will be cleared before released.
this_program
set_encrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for encrypting with the given
key
. The key
memory will be cleared before released.
this_program
set_iv(string(8bit)
iv
)
Set the initialization vector to iv
. The iv
memory will be
cleared before released.
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
Implementation of the Cipher Feed-Back mode (CFB).
Requires Nettle 3.4 or later.
CBC
, GCM
inherit BufferedCipher : BufferedCipher
State
res = Nettle.BlockCipher()
()
Returns a new State
object.
string(8bit)
name()
Returns the base cipher name appended with the string ".CFB"
.
The state for a CFB instance.
inherit BufferedCipher::State : State
object
Nettle.BlockCipher.CFB.State.obj
Read only
int(1..)
block_size()
Returns the block size of the encapsulated cipher.
Nettle.BlockCipher.CFB.State Nettle.BlockCipher.CFB.State()
Initialize the CFB state with the Cipher::State
object
returned by substate_factory()
. This is usually
the State for the cipher implemented in the parent module.
string(8bit)
crypt(string(8bit)
data
)
Encrypt/decrypt data
and return the result. data
must
be an integral number of blocks.
The length of data
MUST be a multiple of the block size
for all calls except the last.
Neither the input or output data is not automatically memory
scrubbed, unless String.secure
has been called on the data.
update()
, digest()
int(1..)
iv_size()
Returns the size for the initialization vector
int(1..)
key_size()
Returns the key size of the encapsulated cipher.
string(8bit)
name()
Returns the string "CFB(x)"
where x is the
encapsulated algorithm.
this_program
set_decrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for decrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_encrypt_key()
, set_iv()
this_program
set_encrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for encrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_decrypt_key()
, set_iv()
this_program
set_iv(string(8bit)
iv
)
Set the initialization vector to iv
. The iv
memory will be
cleared before released.
iv
must have the length reported by iv_size()
.
set_encrypt_key()
, set_decrypt_key()
.
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
Implementation of the Counter mode (CTR).
This cipher mode works like a stream cipher with a block size >= 1. This means that the same key and initialization vector (aka counter) should never be reused, since a simple xor would reveal information about the plain text. It also means that it should never be used without a suiteable Message Authentication Code (MAC).
CBC
, GCM
, Buffer
inherit __builtin.Nettle.Cipher : Cipher
State
res = Nettle.BlockCipher()
()
Returns a new State
object.
string(8bit)
name()
Returns the base cipher name appended with the string ".CTR"
.
The state for a CTR instance.
inherit Cipher::State : State
object
Nettle.BlockCipher.CTR.State.obj
Read only
int(1..)
block_size()
Returns the block size of the encapsulated cipher.
Nettle.BlockCipher.CTR.State Nettle.BlockCipher.CTR.State()
Initialize the CTR state with the Cipher::State
object
returned by substate_factory()
. This is usually
the State for the cipher implemented in the parent module.
string(8bit)
crypt(string(8bit)
data
)
Encrypt/decrypt data
and return the result. data
must
be an integral number of blocks.
The length of data
MUST be a multiple of the block size
for all calls except the last.
Neither the input or output data is not automatically memory
scrubbed, unless String.secure
has been called on the data.
update()
, digest()
int(1..)
iv_size()
Returns the size for the initialization vector
int(1..)
key_size()
Returns the key size of the encapsulated cipher.
string(8bit)
name()
Returns the string "CTR(x)"
where x is the
encapsulated algorithm.
this_program
set_decrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for decrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_encrypt_key()
, set_iv()
this_program
set_encrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for encrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_decrypt_key()
, set_iv()
this_program
set_iv(string(8bit)
iv
)
Set the initialization vector to iv
. The iv
memory will be
cleared before released.
iv
must have the length reported by iv_size()
.
set_encrypt_key()
, set_decrypt_key()
.
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
Implementation of the Infinite Garble Extension mode (IGE).
This is a mode of operation suggested in 1977 by C. Cambell.
CBC
, GCM
, CFB
inherit BufferedCipher : BufferedCipher
inherit Cipher::State : State
int(1..)
block_size()
Returns the block size of the encapsulated cipher.
Nettle.BlockCipher.IGE.State Nettle.BlockCipher.IGE.State()
Initialize the IGE state with the Cipher::State
object
returned by substate_factory()
. This is usually
the State for the cipher implemented in the parent module.
string(8bit)
crypt(string(8bit)
data
)
Encrypt/decrypt data
and return the result. data
must
be an integral number of blocks.
Neither the input or output data is not automatically memory
scrubbed, unless String.secure
has been called on the data.
int(1..)
iv_size()
Returns the size for the initialization vector
int(1..)
key_size()
Returns the key size of the encapsulated cipher.
string(8bit)
name()
Returns the string "IGE(x)"
where x is the
encapsulated algorithm.
this_program
set_decrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for decrypting with the given
key
. The key
memory will be cleared before released.
this_program
set_encrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for encrypting with the given
key
. The key
memory will be cleared before released.
this_program
set_iv(string(8bit)
iv
)
Set the initialization vector to iv
. The iv
memory will be
cleared before released.
IGE semantically has two initialization vectors of size
block_size()
; x0 (previous plaintext) and y0
(previous ciphertext). They are here concatenated to a single
initialization vector of double the block size.
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
Implementation of the Output Feed-Back mode (OFB).
This cipher mode works like a stream cipher with a block size >= 1. This means that the same key and initialization vector (aka counter) should never be reused, since a simple xor would reveal information about the plain text. It also means that it should never be used without a suiteable Message Authentication Code (MAC).
CFB
, CBC
, CTR
, GCM
inherit BufferedCipher : BufferedCipher
State
res = Nettle.BlockCipher()
()
Returns a new State
object.
string(8bit)
name()
Returns the base cipher name appended with the string ".OFB"
.
The state for a OFB instance.
inherit BufferedCipher::State : State
object
Nettle.BlockCipher.OFB.State.obj
Read only
int(1..)
block_size()
Returns the block size of the encapsulated cipher.
Nettle.BlockCipher.OFB.State Nettle.BlockCipher.OFB.State()
Initialize the OFB state with the Cipher::State
object
returned by substate_factory()
. This is usually
the State for the cipher implemented in the parent module.
string(8bit)
crypt(string(8bit)
data
)
Encrypt/decrypt data
and return the result. data
must
be an integral number of blocks.
The length of data
MUST be a multiple of the block size
for all calls except the last.
Neither the input or output data is not automatically memory
scrubbed, unless String.secure
has been called on the data.
update()
, digest()
int(1..)
iv_size()
Returns the size for the initialization vector
int(1..)
key_size()
Returns the key size of the encapsulated cipher.
string(8bit)
name()
Returns the string "OFB(x)"
where x is the
encapsulated algorithm.
this_program
set_decrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for decrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_encrypt_key()
, set_iv()
this_program
set_encrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for encrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_decrypt_key()
, set_iv()
this_program
set_iv(string(8bit)
iv
)
Set the initialization vector to iv
. The iv
memory will be
cleared before released.
iv
must have the length reported by iv_size()
.
set_encrypt_key()
, set_decrypt_key()
.
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
Implementation of the Propagating Cipher Block Chaining mode (PCBC).
This mode is also known as plaintext cipher block chaining (from Kerberos v4).
Works as a wrapper for the cipher implemented by overloading
the parent class (Cipher
).
CBC
, GCM
inherit CBC : CBC
inherit CBC::State : State
string(8bit)
crypt(string(8bit)
data
)
Encrypt/decrypt data
and return the result. data
must
be an integral number of blocks.
Neither the input nor the output data is automatically memory
scrubbed, unless String.secure
has been called on the data.
string(8bit)
name()
Returns the string "PCBC(x)"
where x is the
encapsulated algorithm.
This is the BlockCipher
class extended with algorithms
that require a block size of 16
bytes.
Cipher
, BlockCipher
, BufferedCipher
, GCM
inherit BlockCipher : BlockCipher
inherit __builtin.Nettle.BlockCipher16Mixin : BlockCipher16Mixin
Base class for cipher contexts for ciphers that have a block size of 16 bytes.
inherit BlockCipher::State : State
string(8bit)
unwrap_key(string(8bit)
wrap
, bool
|void
method
)
The AES Key Unwrapping algorithms from RFC 3394 and RFC 5649.
wrap
Wrapped key to unwrap.
method
Method that was used to wrap wrap
. See wrap_key()
for details.
| |
|
This function is intended to be used to decode encryption keys
that have been wrapped by wrap_key()
.
Returns the unwrapped key.
Throws an error on failure to unwrap the key.
Assumes that the State
object has been initialized to
decryption mode (ie that set_decrypt_key()
has been called).
RFC 6931 section 2.6.3 indicates that the RFC 3394 algorithm
is also appropriate for Camellia
.
wrap_key()
string(8bit)
wrap_key(string(8bit)
key
, bool
|void
method
)
key
Key to wrap.
method
Method to use to wrap the key. One of:
| RFC 3394 This algorithm is intended to be used to encode encryption keys which are a multiple of 8 bytes and at least 16 bytes long. This is the default method. |
| RFC 5649 This algorithm is similar to the above, but supports keys of any length and has an intentionally not compatible result. |
Returns the wrapped key.
Assumes that the State
object has been initialized to
encryption mode (ie that set_encrypt_key()
has been called).
RFC 6931 section 2.6.3 indicates that the RFC 3394 algorithm
is also appropriate for Camellia
.
unwrap_key()
Implementation of the Counter with Cipher Block Chaining Message Authentication Code mode (CCM).
Works as a wrapper for the cipher implemented by overloading
the parent class (BlockCipher16
).
This is a so-called authenticated encryption with associated data (AEAD) algorithm, and in addition to encryption also provides message digests.
The operation of CCM is specified in NIST Special Publication 800-38C.
This mode of operation is not suited for streaming operation,
as the sizes of the associated data and payload data need to
be known for the CBC-MAC operation to start. Currently this
means that the associated data and payload data are buffered
until State()->digest()
is called.
CCM8
, CBC
, GCM
, CTR
inherit __builtin.Nettle.AEAD : AEAD
inherit BlockCipher::CTR : CTR
int(4..16)
digest_size()
Default digest size.
Returns 16
, but overloading via inherit is supported,
and may return any even number in the range [4..16]
.
Note that the digest length is folded into the digest, so it doesn't simply imply a truncation.
string(8bit)
name()
Returns the name of the base cipher with ".CCM"
appended.
inherit CTR::State : State
Nettle.BlockCipher16.CCM.State Nettle.BlockCipher16.CCM.State()
string(8bit)
digest(int(4..16)
|void
bytes
)
Returns the CBC-MAC digest of the specified size.
bytes
Size in bytes for the desired digest. Any even number in
the range [4..16]
. If not specified the value from
calling digest_size()
will be used.
Note that the digest length is folded into the digest, so it doesn't simply imply a truncation.
digest_size()
, global::digest_size()
int(4..16)
digest_size()
Default digest size.
This function is used by digest()
to determine the digest
size if no argument was given.
The default implementation returns the result from calling
global::digest_size()
, but overloading via inherit is supported,
and may return any even number in the range [4..16]
.
Note that the digest length is folded into the digest, so it doesn't simply imply a truncation.
digest()
, CCM::digest_size()
Special case of CCM
where the default digest size
has been truncated to 8
bytes.
CCM
, CBC
, GCM
, CTR
inherit CCM : CCM
int(4..16)
digest_size()
Default digest size.
Returns 8
, but overloading via inherit is supported,
and may return any even number in the range [4..16]
.
string(8bit)
name()
Returns the name of the base cipher with ".CCM8"
appended.
CMAC - Cipher-based Message Authentication Code
This module implements the CMAC algorithm from RFC 4493.
Requires Nettle 3.5 or later.
inherit __builtin.Nettle.MAC : MAC
string(8bit)
name()
Returns the name of the base cipher with ".CMAC"
appended.
inherit Cipher::State : State
Nettle.BlockCipher16.CMAC.State Nettle.BlockCipher16.CMAC.State()
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
Implementation of the EAX mode.
Works as a wrapper for the cipher implemented by overloading
the parent class (BlockCipher16
).
This is a so-called authenticated encryption with associated data (AEAD) algorithm, and in addition to encryption also provides message digests.
This mode of operation was specified as a reaction to the
limitiations of the BlockCipher16.CCM
mode.
Requires Nettle 3.0 or later.
CBC
, CTR
, BlockCipher16.CCM
, BlockCipher16.GCM
inherit __builtin.Nettle.AEAD : AEAD
int(1..)
digest_size()
Default digest size.
Returns BlockCipher::block_size()
, but overloading via
inherit is supported, and may return any positive number
<= BlockCipher::block_size()
.
string(8bit)
name()
Returns the name of the base cipher with ".EAX"
appended.
inherit AEAD::State : State
int(16)
block_size()
Returns the block size of the encapsulated cipher,
which is always 16
for EAX.
Nettle.BlockCipher16.EAX.State Nettle.BlockCipher16.EAX.State()
string(8bit)
digest(int(1..16)
|void
bytes
)
Returns the OMAC digest of the specified size.
bytes
Size in bytes for the desired digest. Any number in the
range [1..16]
. If not specified the value from
calling digest_size()
will be used.
digest_size()
, global::digest_size()
int(1..16)
digest_size()
Default digest size.
This function is used by digest()
to determine the digest
size if no argument was given.
The default implementation returns the result from calling
EAX::digest_size()
, but overloading via inherit is supported,
and may return any even number in the range [1..16]
.
digest()
, EAX::digest_size()
int(16)
iv_size()
Returns the recommended size for the initialization vector
(ie 16
).
Other sizes are allowed, but will be compressed or expanded to this size using the encapsulated cipher.
int(1..)
key_size()
Returns the key size of the encapsulated cipher.
string(8bit)
name()
Returns the string "x.EAX"
where x is the
encapsulated algorithm.
this_program
set_decrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for decrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_encrypt_key()
, set_iv()
this_program
set_encrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for encrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_decrypt_key()
, set_iv()
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
Implementation of the Galois Counter Mode (GCM).
Works as a wrapper for the cipher implemented by overloading
the parent class (BlockCipher16
).
This is a so-called authenticated encryption with associated data (AEAD) algorithm, which in addition to encryption also provides message digests.
The operation of GCM is specified in NIST Special Publication 800-38D.
Typically accessed as Crypto.AES.GCM
or
Crypto.Camellia.GCM
Requires Nettle 2.2 or later.
CBC
inherit __builtin.Nettle.AEAD : AEAD
int(16)
block_size()
Returns the block size of the encapsulated cipher,
which is always 16
for GCM.
int(16)
digest_size()
Returns the size of the generated digest,
which is always 16
for GCM.
int(12)
iv_size()
Returns the recommended size for the initialization vector
(ie 12
).
Other sizes are allowed, but will be compressed or expanded to this size using the encapsulated cipher.
string(8bit)
name()
Returns the name of the base cipher with ".GCM"
appended.
The state for a GCM instance.
inherit AEAD::State : State
int(16)
block_size()
Returns the block size of the encapsulated cipher,
which is always 16
for GCM.
Nettle.BlockCipher16.GCM.State Nettle.BlockCipher16.GCM.State()
Initialize the GCM state with the Cipher::State
object
returned by substate_factory()
. This is usually
the State for the cipher implemented in the parent module.
string(8bit)
crypt(string(8bit)
data
)
Encrypt/decrypt data
and return the result. data
must
be an integral number of blocks.
The length of data
MUST be a multiple of the block size
(ie 16
) for all calls except the last.
Neither the input or output data is not automatically memory
scrubbed, unless String.secure
has been called on the data.
update()
, digest()
string(8bit)
digest()
Generate a message digest for the data accumulated so far.
set_iv()
needs to be called to start the next message.
update()
, digest()
int(16)
digest_size()
Returns the size of the generated digest,
which is always 16
for GCM.
int(12)
iv_size()
Returns the recommended size for the initialization vector
(ie 12
).
Other sizes are allowed, but will be compressed or expanded to this size using the encapsulated cipher.
int(1..)
key_size()
Returns the key size of the encapsulated cipher.
string(8bit)
name()
Returns the string "x.GCM"
where x is the
encapsulated algorithm.
this_program
set_decrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for decrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_encrypt_key()
, set_iv()
this_program
set_encrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for encrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_decrypt_key()
, set_iv()
this_program
set_iv(string(8bit)
iv
)
Set the initialization vector to iv
. The iv
memory will be
cleared before released.
Also resets all state needed to start a new message.
For iv
s of length other than 12
, an encryption or
decryption key must have been set first.
set_encrypt_key()
, set_decrypt_key()
.
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
void
update(string(8bit)
public_data
)
Add public_data
to be authenticated.
The length of public_data
MUST be a multiple of the
block size (ie 16
) for all calls except the last.
All calls of update()
need to be performed before
any calls of crypt()
.
Implementation of the OCB mode (RFC 7253).
Works as a wrapper for the cipher implemented by overloading
the parent class (BlockCipher16
).
OCB was initially an acronym for Offset CodeBook.
This is a so-called authenticated encryption with associated data (AEAD) algorithm, and in addition to encryption also provides message digests.
This module requires Nettle 3.9 or later.
CBC
, CTR
, BlockCipher16.CCM
, BlockCipher16.GCM
inherit __builtin.Nettle.AEAD : AEAD
int(16)
digest_size()
Default digest size (16).
string(8bit)
name()
Returns the name of the base cipher with ".OCB"
appended.
inherit AEAD::State : State
int(16)
block_size()
Returns the block size of the encapsulated cipher,
which is always 16
for OCB.
Nettle.BlockCipher16.OCB.State Nettle.BlockCipher16.OCB.State()
string(8bit)
digest()
Returns the OCB authentication tag.
The size of the digest is specified in the call to
set_iv()
.
set_iv()
, digest_size()
, global::digest_size()
int(1..16)
digest_size()
Digest size as set by set_iv()
.
digest()
, OCB::digest_size()
int(15)
iv_size()
Returns the recommended size for the initialization vector
(ie 15
).
Other sizes are allowed, but will be compressed or expanded to this size using the encapsulated cipher.
int(1..)
key_size()
Returns the key size of the encapsulated cipher.
string(8bit)
name()
Returns the string "x.OCB"
where x is the
encapsulated algorithm.
this_program
set_decrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for decrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_encrypt_key()
, set_iv()
this_program
set_encrypt_key(string(8bit)
key
, int
|void
flags
)
Prepare the cipher and the wrapper for encrypting with the given
key
. The key
memory will be cleared before released.
Note that this operation does not by itself reset the
context sufficiently to start a new message; set_iv()
needs to be called too.
set_decrypt_key()
, set_iv()
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
Extends the Cipher
class with the Buffer
meta cipher. This is in turn inherited by the
BlockCipher
class, which is the base class
for all block ciphers.
inherit Cipher : Cipher
Acts as a buffer so that data can be fed to the cipher in blocks that don't correspond to cipher block sizes.
class Encrypter { protected Crypto.Cipher buffer;
void create(string key) { buffer = Crypto.AES.CBC.Buffer(); buffer->set_encrypt_key(key); }
string feed(string data) { return buffer->crypt(data); }
string drain() { return buffer->pad(Crypto.PAD_PKCS7); } }
BlockCipher.CBC
, BlockCipher16.GCM
inherit __builtin.Nettle.Cipher : Cipher
State
res = Nettle.BufferedCipher()
()
Returns a new State
object.
Acts as a buffer so that data can be fed to the cipher in blocks that don't correspond to cipher block sizes.
class Encrypter { protected Crypto.Cipher buffer;
void create(string key) { buffer = Crypto.AES.CBC.Buffer(); buffer->set_encrypt_key(key); }
string feed(string data) { return buffer->crypt(data); }
string drain() { return buffer->pad(Crypto.PAD_PKCS7); } }
BlockCipher.CBC
, BlockCipher16.GCM
int(1..)
block_size()
Get the block size of the contained block crypto.
Nettle.BufferedCipher.Buffer.State Nettle.BufferedCipher.Buffer.State()
Initialize the buffer with the Cipher::State
object
returned by substate_factory()
. This is usually
the State for the cipher implemented in the parent module.
string(8bit)
crypt(string(8bit)
data
)
Encrypt or decrypt some data.
Adds data to be en/decrypted to the buffer. If there's enough data to en/decrypt a block, that will be done, and the result returned. Any unprocessed data will be left in the buffer.
Neither the input or output data is not automatically memory
scrubbed, unless String.secure
has been called on the data.
int(0..)
iv_size()
Get the iv size of the contained block crypto.
int(1..)
key_size()
Get the key size of the contained block crypto.
string(8bit)
name()
Returns the name of the wrapped cipher with ".Buffer"
appended.
string(8bit)
pad(void
|int
method
)
Pad and encrypt any data left in the buffer. The output data is
not automatically memory scrubbed, unless String.secure
is
called on the data.
method
The type of padding to apply to the buffer.
| Pads according to ISO 10126, which means filling all extra space with random data and putting the size of the non-payload data last. |
| Pads according to RFC 5246 section 6.2.3.2, meaning that all extra space is filled with the size of the padding. Note that this size has an off by one difference to the other schemas, so 0 means 1 byte of padding. |
| |
| Pads according to ANSI X.923, which means filling all extra space with zero and putting the size of the non-payload data last. |
| Pads according to PKCS7 / RFC 3852, which means filling all extra space with the size of the extra space. |
| Fills the extra space with null bytes. To correctly remove
the padding the clear text data must not end with a null
byte. In that case the data would have to be manually
padded/unpadded before/after calling |
Defaults to Crypto.PAD_SSL for compatibility reasons.
unpad()
this_program
set_decrypt_key(string(8bit)
key
, void
|int
flags
)
Set the decryption key. The key
memory will be cleared before
released.
As a side-effect any buffered data will be cleared.
this_program
set_encrypt_key(string(8bit)
key
, void
|int
flags
)
Set the encryption key. The key
memory will be cleared before
released.
As a side-effect any buffered data will be cleared.
this_program
set_iv(string(8bit)
iv
)
Set the initialization vector to iv
.
Cipher::State
substate_factory()
Returns the Cipher::State
object that this object
is to operate on.
Defaults to creating the State for the cipher implemented in the parent module.
string(8bit)
unpad(string(8bit)
data
, void
|int
method
)
Decrypt and unpad a block of data. Neither the input or output
data is not automatically memory scrubbed, unless
String.secure
has been called on the data.
This performs the reverse operation of pad()
. The padding
will be verified to be correct, if possible. If not, zero is
returned.
method
The type of padding that was applied to the original buffer.
|
|
|
|
|
|
Defaults to Crypto.PAD_SSL for compatibility reasons.
pad()
Implementation of the CAMELLIA cipher.
Requires Nettle 2.1 or later.
inherit BlockCipher16 : BlockCipher16
State for CAMELLIA encyption.
inherit BlockCipher16::State : State
Implementation of the CAST128 cipher.
inherit BlockCipher : BlockCipher
State for CAST128 encyption.
inherit BlockCipher::State : State
Implementation of the CHACHA stream cipher.
Note that this class is not available in all versions of Nettle.
inherit BlockCipher : BlockCipher
State for CHACHA encyption.
inherit Cipher::State : State
string(8bit)
crypt(string(8bit)
data
)
Encrypts or decrypts data, using the current key. Neither the
input nor output data is automatically memory scrubbed,
unless String.secure
has been called on them.
data
Usually an integral number of blocks, except for the last segement in a run. The decoder must get partial blocks at the same places as the encoder, otherwise they will get out of sync.
The encrypted or decrypted data.
object
set_iv(string(8bit)
iv
)
Set the initialization vector (aka nonce) and reset the block counter to zero.
iv
An 8-byte long string which is only to be used once for every key.
This function MUST be called in addition to
set_encrypt_key()
or set_decrypt_key()
.
The same iv
should NEVER be reused with the same key!
Implementation of the CHACHA_POLY1305 AEAD algorithm.
inherit AEAD : AEAD
State for CHACHA_POLY1305 encyption.
inherit AEAD::State : State
Represents information about a cipher algorithm, such as name, key size, and block size.
inherit __builtin.Nettle.Cipher : Cipher
int(1..)
block_size()
The block size of the cipher (1 for stream ciphers).
int(1..)
key_size()
The recommended key size for the cipher.
string(8bit)
name()
A human readable name for the algorithm.
Base class for cipher contexts.
inherit Cipher::State : State
int(1..)
block_size()
The block size for this cipher.
The default implementation just calls Cipher::block_size()
in the parent.
string(8bit)
crypt(string(8bit)
data
)
Encrypts or decrypts data, using the current key. Neither the
input nor output data is automatically memory scrubbed,
unless String.secure
has been called on them.
data
For block ciphers, data must be an integral number of blocks.
The encrypted or decrypted data.
int(1..)
key_size()
The actual key size for this cipher.
string(8bit)
make_key()
Generate a key by calling random_string
and initialize this
object for encryption with that key.
The generated key. The key memory will be cleared before being released.
set_encrypt_key
string(8bit)
name()
A human readable name for the algorithm.
The default implementation just calls Cipher::name()
in the parent.
State
set_decrypt_key(string(8bit)
key
, void
|int
flags
)
Initializes the object for decryption. The key
memory will be
cleared before released.
set_encrypt_key
, crypt
State
set_encrypt_key(string(8bit)
key
, void
|int
flags
)
Initializes the object for encryption. The key
memory will be
cleared before released.
set_decrypt_key
, crypt
Elliptic Curve Definition for the curve
y^2 = x^3 + 486662 x^2 + x (mod 2^255 - 19)
.
This curve is standardized in RFC 7748.
The API for this curve differs somewhat from the API
used by the other Curve
s.
Requires Nettle 3.1 or later.
Curve
, Curve448
, RFC 7748
inherit __builtin.Nettle.ECC_Curve : ECC_Curve
Point
res = Nettle.Curve25519()
* scalar
Multiply the curve by a scalar.
This can be used to get the public key from a private key.
Returns a new point on the curve.
string(7bit)
jose_name()
Returns the name of the curve according to JOSE (RFC 8037 section 3.1).
Returns the string "X25519"
.
name()
string(7bit)
name()
Returns the name of the curve.
Gmp.mpz
new_scalar(function
(int(0..)
:string(8bit)
) rnd
)
rnd
Randomness function to use as source.
Returns a random scalar suitable to use as an ECDSA
private key
or as an ECDH exponent.
string(8bit)
point_mul(string(8bit)
x
, string(8bit)
scalar
)
Multiply a point on the curve by a scalar.
A typical use is for Elliptic Curve Diffie Hellman (ECDH) key exchange.
Returns the new point on the curve.
int
size()
Returns the size in bits for a single coordinate on the curve.
Edwards Curve Digital Signing Algorithm
Requires Nettle 3.1 or later.
inherit Point : Point
This point represents the public key.
inherit __builtin.Nettle.Sign : Sign
void
generate_key()
Generate a new set of private and public keys on the current curve.
Curve25519
get_curve()
Get the elliptic curve that is in use.
string(8bit)
get_private_key()
Get the private key.
string(8bit)
get_x()
Get the x coordinate of the public key.
string(7bit)
jose_name()
Returns the string "Ed25519"
.
string(7bit)
name()
Returns the string "EdDSA"
.
string(8bit)
raw_sign(string(8bit)
message
)
Sign the message
.
bool
raw_verify(string(8bit)
message
, string(8bit)
signature
)
Verify the signature
against the message
.
void
set_private_key(string(8bit)
k
)
Set the private key (and corresponding public key).
Throws errors if the key isn't valid for the curve.
void
set_public_key(string(8bit)
x
)
Change to the selected point on the curve as public key.
Throws errors if the point isn't on the curve.
void
set_random(function
(int(0..)
:string(8bit)
) r
)
Set the random function, used to generate keys and parameters,
to the function r
.
A point on an elliptic curve.
inherit ECC_Curve::Point : Point
Elliptic Curve Definition for the curve
y^2 = x^3 + 156326 x^2 + x (mod 2^448 - 2^224 - 1)
.
This curve is standardized in RFC 7748.
The API for this curve differs somewhat from the API
used by the other Curve
s.
Requires Nettle 3.6 or later.
Crypto.ECC.Curve
, Curve25519
, RFC 7748
inherit __builtin.Nettle.ECC_Curve : ECC_Curve
Point
res = Nettle.Curve448()
* scalar
Multiply the curve by a scalar.
This can be used to get the public key from a private key.
Returns a new point on the curve.
string(7bit)
jose_name()
Returns the name of the curve according to JOSE (RFC 8037 section 3.1).
Returns the string "X448"
.
name()
string(7bit)
name()
Returns the name of the curve.
Gmp.mpz
new_scalar(function
(int(0..)
:string(8bit)
) rnd
)
rnd
Randomness function to use as source.
Returns a random scalar suitable to use as an ECDSA
private key
or as an ECDH exponent.
string(8bit)
point_mul(string(8bit)
x
, string(8bit)
scalar
)
Multiply a point on the curve by a scalar.
A typical use is for Elliptic Curve Diffie Hellman (ECDH) key exchange.
Returns the new point on the curve.
int
size()
Returns the size in bits for a single coordinate on the curve.
Edwards Curve Digital Signing Algorithm
Requires Nettle 3.6 or later.
inherit Point : Point
This point represents the public key.
inherit __builtin.Nettle.Sign : Sign
void
generate_key()
Generate a new set of private and public keys on the current curve.
Curve448
get_curve()
Get the elliptic curve that is in use.
string(8bit)
get_private_key()
Get the private key.
string(8bit)
get_x()
Get the x coordinate of the public key.
string(7bit)
jose_name()
Returns the string "Ed448"
.
string(7bit)
name()
Returns the string "EdDSA"
.
string(8bit)
raw_sign(string(8bit)
message
)
Sign the message
.
bool
raw_verify(string(8bit)
message
, string(8bit)
signature
)
Verify the signature
against the message
.
void
set_private_key(string(8bit)
k
)
Set the private key (and corresponding public key).
Throws errors if the key isn't valid for the curve.
void
set_public_key(string(8bit)
x
)
Change to the selected point on the curve as public key.
Throws errors if the point isn't on the curve.
void
set_random(function
(int(0..)
:string(8bit)
) r
)
Set the random function, used to generate keys and parameters,
to the function r
.
A point on an elliptic curve.
inherit ECC_Curve::Point : Point
Implementation of the Data Encryption Standard (DES) crypto algorithm.
inherit BlockCipher : BlockCipher
string(8bit)
fix_parity(string(8bit)
key
)
Sets the last bit in every byte in key
to reflect the parity.
If a seven byte key is used, it will be expanded into eight
bytes. If a key longer than eight characters is used, it will
be truncated to eight characters.
State for DES encyption
inherit Cipher::State : State
string(8bit)
fix_parity(string(8bit)
key
)
Sets the last bit in every byte in key
to reflect the parity.
If a seven byte key is used, it will be expanded into eight
bytes. If a key longer than eight characters is used, it will
be truncated to eight characters.
Implementation of the DES3 cipher algorithm.
inherit BlockCipher : BlockCipher
string(8bit)
fix_parity(string(8bit)
key
)
Sets the last bit in every byte in key
to reflect the parity.
If a 21 byte key is used, it will be expanded into 24
bytes. If a key longer than 24 characters is used, it will
be truncated to 24 characters.
State for DES3 encyption
inherit Cipher::State : State
Diffie-Hellman Parameters.
Gmp.mpz
Nettle.DH_Params.g
Generator.
Gmp.mpz
Nettle.DH_Params.p
Prime.
Gmp.mpz
Nettle.DH_Params.q
Order.
void
generate(int
p_bits
, int
q_bits
, function
(int(0..)
:string(8bit)
) rnd
)
Generate a new set of Diffie-Hellman parameters.
Throws errors for unsupported parameters.
This function is not available in all installations of Pike.
array
(Gmp.mpz
) generate_keypair(function
(int(0..)
:string(8bit)
) rnd
)
Generate a Diffie-Hellman key pair.
Returns the following array:
Array | |
| The generated public key. |
| The corresponding private key. |
Elliptic Curve Definition
inherit __builtin.Nettle.ECC_Curve : ECC_Curve
inherit ECDSA : ECDSA
This point represents the public key.
Requires Nettle 3.6 or later.
Point
res = Nettle.ECC_Curve()
* scalar
Multiply the curve by a scalar.
This can be used to get the public key from a private key.
Returns a new Point
on the curve.
bool
res = Nettle.ECC_Curve()
== x
Returns 1
if x
is the same Curve
,
and 0
(zero) otherwise.
Nettle.ECC_Curve Nettle.ECC_Curve(
int(0..)
curve
)
Initialize the curve.
curve
The curve type the object should be initialized as.
|
|
|
|
|
|
|
string(7bit)
jose_name()
Returns the name of the curve according to JOSE (RFC 7518 section 6.2.1.1).
Returns the JOSE name for supported curves,
and UNDEFINED
otherwise.
name()
string(7bit)
name()
Returns the name of the curve.
jose_name()
Gmp.mpz
new_scalar(function
(int(0..)
:string(8bit)
) rnd
)
rnd
Randomness function to use as source.
Returns a random scalar suitable to use as an ECDSA
private key
or as an ECDH secret factor.
Point
point_mul(Gmp.mpz
|int
x
, Gmp.mpz
|int
y
, Gmp.mpz
|int
scalar
)
Multiply a point on the curve by a scalar.
A typical use is for Elliptic Curve Diffie Hellman (ECDH) key exchange.
This is equivalent to (Point(x, y) * scalar)
.
Returns the new Point
on the curve.
Throws an error if the point (x
, y
) isn't on the curve.
array
(Gmp.mpz
) raw_sign(string(8bit)
digest
)
Sign the message digest digest
. Returns the signature
as two Gmp.mpz
objects.
bool
raw_verify(string(8bit)
digest
, Gmp.mpz
r
, Gmp.mpz
s
)
Verify the signature r
, s
against the message digest digest
.
int
size()
Returns the size in bits for a single coordinate on the curve.
Elliptic Curve Digital Signing Algorithm
inherit Point : Point
This point represents the public key.
inherit __builtin.Nettle.Sign : Sign
void
generate_key()
Generate a new set of private and public keys on the current curve.
ECC_Curve
get_curve()
Get the elliptic curve that is in use.
Gmp.mpz
get_private_key()
Get the private key.
Gmp.mpz
get_x()
Get the x coordinate of the public key.
get_y()
Gmp.mpz
get_y()
Get the y coordinate of the public key.
get_x()
string(7bit)
name()
Returns the string "ECDSA"
followed by
the parenthesized name of the curve.
array
(Gmp.mpz
) raw_sign(string(8bit)
digest
)
Sign the message digest digest
. Returns the signature
as two Gmp.mpz
objects.
bool
raw_verify(string(8bit)
digest
, Gmp.mpz
r
, Gmp.mpz
s
)
Verify the signature r
, s
against the message digest digest
.
void
set_private_key(Gmp.mpz
|int
k
)
Set the private key (and corresponding public key).
Throws errors if the key isn't valid for the curve.
void
set_public_key(Gmp.mpz
|int
x
, Gmp.mpz
|int
y
)
Change to the selected point on the curve as public key.
Throws errors if the point isn't on the curve.
void
set_random(function
(int(0..)
:string(8bit)
) r
)
Set the random function, used to generate keys and parameters,
to the function r
.
A point on an elliptic curve.
inherit ECC_Curve::Point : Point
bool
equal(Nettle.ECC_Curve.Point from, mixed
x
)
Returns 1
if x
is a Point
on the same
Curve
and has the same coordinates, and otherwise
returns 0
(zero).
Point
res = Nettle.ECC_Curve.Point()
* scalar
Multiply the point on the curve by a scalar.
A typical use is for Elliptic Curve Diffie Hellman (ECDH) key exchange.
Returns the new point on the curve.
ECC_Curve
get_curve()
Get the elliptic curve that is in use.
Gmp.mpz
get_x()
Get the x coordinate of the point.
get_y()
Gmp.mpz
get_y()
Get the y coordinate of the point.
get_x()
string(7bit)
name()
Returns the string "Point"
followed by
the parenthesized name of the curve.
void
set(Gmp.mpz
|int
x
, Gmp.mpz
|int
y
)
Change to the selected point on the curve.
Throws errors if the point isn't on the curve.
Implements the Fortuna PRNG generator, designed by Niels Ferguson and Bruce Schneier and described in Practical Cryptography. Web published exerpt at https://www.schneier.com:443/fortuna.pdf
This implementation uses AES256 to generate output and SHA256 to generate keys.
To use this class an entropy accumulator needs to be implemented
and supply the reseed()
method with new entopy.
string(8bit)
random_string(int(0..)
len
)
Generates len
amount of pseudo random data. In contrast with
the Fortuna PseudoRandomData function, which only allows 2^20
bytes of random data per call, the necessary rekey operations
are here performed internally, so no such restrictions apply.
void
reseed(string(8bit)
data
)
Updated the internal key with the provided additional entropy.
Implementation of the GOST94 hash algorithm.
Requires Nettle 2.6 or later.
inherit Hash : Hash
State for GOST94 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the GOST94 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.GOST94.HMAC.GOST94 Nettle.GOST94.HMAC.GOST94(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the GOST94CP hash algorithm.
Requires Nettle 3.6 or later.
inherit Hash : Hash
State for GOST94CP hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the GOST94CP hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.GOST94CP.HMAC.GOST94CP Nettle.GOST94CP.HMAC.GOST94CP(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Represents information about a hash algorithm, such as name, digest size, and internal block size.
inherit __builtin.Nettle.Hash : Hash
string(7bit)
balloon(string(8bit)
password
, string(8bit)
salt
, int(1..)
s_cost
, int(1..)
rounds
)
Password hashing function in crypt_hash()
-style.
Implements the algorithm described in https://eprint.iacr.org/2016/027.pdf.
password
Password to hash.
salt
Salt for the password.
s_cost
Memory cost.
rounds
Number of rounds (also known as t_cost).
Returns the balloon hash of the password.
The password
memory will be cleared before released.
Requires Nettle 3.9 or later.
crypt_hash()
int(1..)
block_size()
Returns the internal block size of the hash algorithm.
string(7bit)
crypt_hash(string(8bit)
password
, string(8bit)
salt
, int(0..)
rounds
)
Password hashing function in crypt_md5()
-style.
Implements the algorithm described in http://www.akkadia.org/drepper/SHA-crypt.txt.
This is the algorithm used by crypt(2) in methods $5$ (SHA256) and $6$ (SHA512).
The password
memory will be cleared before released.
Rounds will never be set to less than 1000. If rounds
is 0
it will be set to 5000.
In Pike 8.0.1876 and earlier this function generated incompatible
hashes for passwords that had a length that was a power of 2.
See crypt_hash_pike()
for details.
crypt_md5()
, crypt_hash_pike()
string(7bit)
crypt_hash_pike(string(8bit)
password
, string(8bit)
salt
, int(0..)
rounds
)
Password hashing function in crypt_md5()
-style.
Almost implements the algorithm described in http://www.akkadia.org/drepper/SHA-crypt.txt.
This function is provided for compatibility with hashes generated by Pike 8.0.1876 and earlier.
It differs from crypt_hash()
for passwords that
have a length that is a power of 2 (phase 11).
The password
memory will be cleared before released.
Rounds will never be set to less than 1000. If rounds
is 0
it will be set to 5000.
Do not use unless you know what you are doing!
crypt_md5()
, crypt_hash()
int(0..)
digest_size()
Returns the size of a hash digest.
string(8bit)
hash(string(8bit)
data
)
Works as a (faster) shortcut for
State()->update(data)->digest()
, where State is
the hash state class corresponding to this Hash.
State()->update()
and State()->digest()
.
string(8bit)
hash(Stdio.File
|Stdio.Buffer
|String.Buffer
|System.Memory
source
, void
|int(0..)
|__deprecated__
(int(..-1)
) bytes
)
Works as a (faster) shortcut for e.g.
State()->update(Stdio.read_file(file))->digest()
,
where State is the hash state class corresponding to this
Hash.
bytes
The number of bytes of the file object file
that should be
hashed. Zero and negative numbers are ignored and the whole file is
hashed. Support for negative numbers is deprecated.
Stdio.File
, State()->update()
and
State()->digest()
.
string(8bit)
name()
Returns a human readable name for the algorithm.
Base class for hashing contexts.
inherit Hash::State : State
string(8bit)
digest(int(0..)
|void
length
)
Generates a digest, and resets the hashing contents.
length
If the length argument is provided, the digest is truncated to the given length.
The digest.
State
update(string(8bit)
data
)
Hashes more data.
Returns this
in order to simplify chaining
of function calls.
Implementation of the IDEA cipher.
inherit BlockCipher : BlockCipher
State for IDEA encyption.
inherit BlockCipher::State : State
Represents information about a MAC algorithm, such as name, key size, digest size, and internal block size.
inherit __builtin.Nettle.MAC : MAC
int(0..)
block_size()
Returns the internal block size of the MAC algorithm.
int(0..)
digest_size()
Returns the size of a MAC digest.
int(0..)
iv_size()
Returns the size of the iv/nonce of the MAC algorithm (if any).
Returns 0
(zero) if there is no configurable iv/nonce.
int(0..)
key_size()
Returns the recommended size for the secret key for the MAC algorithm.
string(8bit)
name()
Returns a human readable name for the algorithm.
Base class for MAC contexts.
inherit MAC::State : State
string(8bit)
res = Nettle.MAC.State()
()
Acts as the combination of update()
followed by digest()
.
Also updates the iv/nonce (if any).
Nettle.MAC.State Nettle.MAC.State(
string(8bit)
key
)
Initialize the MAC with a password.
It also resets any iv/nonce to it's default.
string(8bit)
digest(int
|void
length
)
Generates a digest, and resets the MAC contents.
Also updates the iv/nonce (if any).
length
If the length argument is provided, the digest is truncated to the given length.
The digest.
State
set_iv(string(8bit)
iv
)
Set the iv/nonce (if supported) for the MAC.
Returns this
in order to simplify chaining
of function calls.
State
update(string(8bit)
data
)
Hashes more data.
Returns this
in order to simplify chaining
of function calls.
Implementation of the MD2 hash algorithm.
inherit Hash : Hash
State for MD2 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the MD2 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.MD2.HMAC.MD2 Nettle.MD2.HMAC.MD2(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the MD4 hash algorithm.
inherit Hash : Hash
State for MD4 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the MD4 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.MD4.HMAC.MD4 Nettle.MD4.HMAC.MD4(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the MD5 hash algorithm.
inherit Hash : Hash
State for MD5 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the MD5 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.MD5.HMAC.MD5 Nettle.MD5.HMAC.MD5(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the POLY1305_AES MAC algorithm.
Requires Nettle 3.0 or later.
inherit MAC : MAC
State for POLY1305_AES macing.
inherit MAC::State : State
Implementation of the RIPEMD160 hash algorithm.
Requires Nettle 2.3 or later.
inherit Hash : Hash
State for RIPEMD160 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the RIPEMD160 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.RIPEMD160.HMAC.RIPEMD160 Nettle.RIPEMD160.HMAC.RIPEMD160(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SALSA20 cipher.
Requires Nettle 2.5 or later.
inherit BlockCipher : BlockCipher
State for SALSA20 encyption.
inherit Cipher::State : State
object
set_iv(string(8bit)
iv
)
Set the initialization vector (aka nonce) and reset the block counter to zero.
iv
An 8-byte long string which is only to be used once for every key.
This function MUST be called in addition to
set_encrypt_key()
or set_decrypt_key()
.
The same iv
should NEVER be reused with the same key!
Implementation of the SALSA20
cipher reduced to 12 rounds.
Requires Nettle 2.7 or later.
inherit SALSA20 : SALSA20
Implementation of the SERPENT cipher.
inherit BlockCipher16 : BlockCipher16
State for SERPENT encyption.
inherit BlockCipher16::State : State
Implementation of the SHA1 hash algorithm.
inherit Hash : Hash
State for SHA1 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA1 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA1.HMAC.SHA1 Nettle.SHA1.HMAC.SHA1(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA224 hash algorithm.
inherit Hash : Hash
State for SHA224 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA224 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA224.HMAC.SHA224 Nettle.SHA224.HMAC.SHA224(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA256 hash algorithm.
inherit Hash : Hash
State for SHA256 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA256 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA256.HMAC.SHA256 Nettle.SHA256.HMAC.SHA256(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA384 hash algorithm.
inherit Hash : Hash
State for SHA384 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA384 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA384.HMAC.SHA384 Nettle.SHA384.HMAC.SHA384(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA3_128 hash algorithm.
Requires Nettle 3.10 or later.
inherit Hash : Hash
string(8bit)
shake(string(8bit)
in
, int(0..)
bytes
)
SHAKE-128 hash.
Works as a (faster) shortcut for
SHA3_128.State()->update(in)->shake(bytes)
.
This function is similar to hash()
, but can return an
arbitrary number of bytes. When bytes
is digest_size
the security is equivalent to that of hash()
, albeit
the output is different.
hash()
, State()->update()
and State()->shake()
.
State for SHA3_128 hashing.
inherit Hash::State : State
string(8bit)
shake(int(0..)
bytes
)
SHAKE-128 hash.
This function is similar to hash()
, but can return an
arbitrary number of bytes. When bytes
is digest_size
(or more) the security is equivalent to that of hash()
,
albeit the output is different.
hash()
, State()->update()
, SHA3_128.shake()
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA3_128 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA3_128.HMAC.SHA3_128 Nettle.SHA3_128.HMAC.SHA3_128(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA3_224 hash algorithm.
Requires Nettle 3.2 or later.
inherit Hash : Hash
State for SHA3_224 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA3_224 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA3_224.HMAC.SHA3_224 Nettle.SHA3_224.HMAC.SHA3_224(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA3_256 hash algorithm.
Requires Nettle 3.2 or later.
inherit Hash : Hash
string(8bit)
shake(string(8bit)
in
, int(0..)
bytes
)
SHAKE-256 hash.
Works as a (faster) shortcut for
SHA3_256.State()->update(in)->shake(bytes)
.
This function is similar to hash()
, but can return an
arbitrary number of bytes. When bytes
is digest_size
the security is equivalent to that of hash()
, albeit
the output is different.
hash()
, State()->update()
and State()->shake()
.
State for SHA3_256 hashing.
inherit Hash::State : State
string(8bit)
shake(int(0..)
bytes
)
SHAKE-256 hash.
This function is similar to hash()
, but can return an
arbitrary number of bytes. When bytes
is digest_size
(or more) the security is equivalent to that of hash()
,
albeit the output is different.
hash()
, State()->update()
, SHA3_256.shake()
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA3_256 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA3_256.HMAC.SHA3_256 Nettle.SHA3_256.HMAC.SHA3_256(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA3_384 hash algorithm.
Requires Nettle 3.2 or later.
inherit Hash : Hash
State for SHA3_384 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA3_384 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA3_384.HMAC.SHA3_384 Nettle.SHA3_384.HMAC.SHA3_384(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA3_512 hash algorithm.
Requires Nettle 3.2 or later.
inherit Hash : Hash
State for SHA3_512 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA3_512 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA3_512.HMAC.SHA3_512 Nettle.SHA3_512.HMAC.SHA3_512(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA512 hash algorithm.
inherit Hash : Hash
State for SHA512 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA512 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA512.HMAC.SHA512 Nettle.SHA512.HMAC.SHA512(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA512_224 hash algorithm.
inherit Hash : Hash
State for SHA512_224 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA512_224 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA512_224.HMAC.SHA512_224 Nettle.SHA512_224.HMAC.SHA512_224(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SHA512_256 hash algorithm.
inherit Hash : Hash
State for SHA512_256 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SHA512_256 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SHA512_256.HMAC.SHA512_256 Nettle.SHA512_256.HMAC.SHA512_256(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SM3 hash algorithm.
Requires Nettle 3.8 or later.
inherit Hash : Hash
State for SM3 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the SM3 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.SM3.HMAC.SM3 Nettle.SM3.HMAC.SM3(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the SM4 cipher.
Requires Nettle 3.9 or later.
inherit BlockCipher16 : BlockCipher16
State for SM4 encyption.
inherit BlockCipher16::State : State
Implementation of the STREEBOG256 hash algorithm.
inherit Hash : Hash
State for STREEBOG256 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the STREEBOG256 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.STREEBOG256.HMAC.STREEBOG256 Nettle.STREEBOG256.HMAC.STREEBOG256(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the STREEBOG512 hash algorithm.
inherit Hash : Hash
State for STREEBOG512 hashing.
inherit Hash::State : State
Accellerated implementation of HMAC (Hashing for Message Authenticity Control) with the STREEBOG512 hash algorithm.
Crypto.HMAC
The HMAC hash state.
Nettle.STREEBOG512.HMAC.STREEBOG512 Nettle.STREEBOG512.HMAC.STREEBOG512(
string(8bit)
passwd
, void
|int
b
)
passwd
The secret password (K).
b
Block size. Must 0
(zero) or equal to the block_size()
.
Implementation of the Twofish cipher.
inherit BlockCipher16 : BlockCipher16
State for Twofish encyption.
inherit BlockCipher16::State : State
Implementation of the UMAC128_AES MAC algorithm.
Requires Nettle 2.7 or later.
inherit MAC : MAC
State for UMAC128_AES macing.
inherit MAC::State : State
Implementation of the UMAC32_AES MAC algorithm.
inherit MAC : MAC
State for UMAC32_AES macing.
inherit MAC::State : State
Implementation of the UMAC64_AES MAC algorithm.
Requires Nettle 2.7 or later.
inherit MAC : MAC
State for UMAC64_AES macing.
inherit MAC::State : State
Implementation of the UMAC96_AES MAC algorithm.
Requires Nettle 2.7 or later.
inherit MAC : MAC
State for UMAC96_AES macing.
inherit MAC::State : State
Yarrow is a family of pseudo-randomness generators, designed for cryptographic use, by John Kelsey, Bruce Schneier and Niels Ferguson. Yarrow-160 is described in a paper at http://www.schneier.com/paper-yarrow.html, and it uses SHA1 and triple-DES, and has a 160-bit internal state. Nettle implements Yarrow-256, which is similar, but uses SHA256 and AES to get an internal state of 256 bits.
Nettle.Yarrow Nettle.Yarrow(
void
|int(0..)
sources
)
The number of entropy sources that will feed entropy to the random number generator is given as an argument to Yarrow during instantiation.
update
void
force_reseed()
By calling this function entropy is moved from the slow pool to the fast pool. Read more about Yarrow before using this.
string(8bit)
get_seed()
Returns part of the internal state so that it can be saved for
later seeding. This method is deprecated. Instead read the
min_seed_size
number of bytes from the random_string
method.
seed()
, random_string()
bool
is_seeded()
Returns 1 if the random generator is seeded and ready to generator output. 0 otherwise.
seed
int(0..)
min_seed_size()
Returns the minimal number of characters that the seed
needs to properly seed the random number generator.
seed
int(0..)
needed_sources()
The number of sources that must reach the threshold before a slow reseed will happen.
string(8bit)
random_string(int(0..)
length
)
Returns a pseudo-random string of the requested length
.
Yarrow
seed(string(8bit)
data
)
The random generator needs to be seeded before it can be used.
The seed must be at least 32 characters long. The seed could be
stored from a previous run by inserting the value returned from
previous random_string
call.
Returns the called object.
min_seed_size
, is_seeded
bool
update(string(8bit)
data
, int
source
, int
entropy
)
Inject additional entropy into the random number generator.
create