Skip to main content

7. HMAC-SHA-96 Authentication Protocol

7. HMAC-SHA-96 Authentication Protocol

This section describes the HMAC-SHA-96 authentication protocol. This protocol uses the SHA hash-function which is described in SHA-NIST, in HMAC mode described in RFC 2104, truncating the output to 96 bits.

This protocol is identified by usmHMACSHAAuthProtocol.

Over time, other authentication protocols may be defined either as a replacement of this protocol or in addition to this protocol.

7.1. Mechanisms

The HMAC-SHA-96 authentication protocol provides the following mechanisms:

Data Integrity Support

In support of data integrity, a message digest algorithm is required. A digest is calculated over an appropriate portion of an SNMP message and included as part of the message sent to the recipient.

Data Origin Authentication

In support of data origin authentication and data integrity, a secret value is prepended to the SNMP message prior to computing the digest; the calculated digest is then partially inserted into the message prior to transmission. The prepended secret is not transmitted. The secret value is shared by all SNMP engines authorized to originate messages on behalf of the appropriate user.

7.1.1. Digest Authentication Mechanism

The Digest Authentication Mechanism defined in this memo provides for:

Integrity Verification

Verification of the integrity of a received message, i.e., the message received is the message sent.

The integrity of the message is protected by computing a digest over an appropriate portion of the message. The digest is computed by the originator of the message, transmitted with the message, and verified by the recipient of the message.

User Verification

Verification of the user on whose behalf the message was generated.

A secret value known only to SNMP engines authorized to generate messages on behalf of a user is used in HMAC mode (see RFC 2104). It also recommends the hash-function output used as Message Authentication Code, to be truncated.

7.1.2. Algorithm Details

This mechanism uses the SHA (SHA-NIST) message digest algorithm:

  • A 160-bit SHA digest is calculated in a special (HMAC) way over the designated portion of an SNMP message
  • The first 96 bits of this digest is included as part of the message sent to the recipient
  • The size of the digest carried in a message is 12 octets
  • The size of the private authentication key (the secret) is 20 octets

For the details see section 7.3.

7.2. Elements of the HMAC-SHA-96 Authentication Protocol

This section contains definitions required to realize the authentication module defined in this section of this memo.

7.2.1. Users

Authentication using this authentication protocol makes use of a defined set of userNames. For any user on whose behalf a message must be authenticated at a particular SNMP engine, that SNMP engine must have knowledge of that user. An SNMP engine that wishes to communicate with another SNMP engine must also have knowledge of a user known to that engine, including knowledge of the applicable attributes of that user.

A user and its attributes are defined as follows:

<userName>

A string representing the name of the user.

<authKey>

A user's secret key to be used when calculating a digest. It MUST be 20 octets long for SHA.

7.2.2. msgAuthoritativeEngineID

The msgAuthoritativeEngineID value contained in an authenticated message specifies the authoritative SNMP engine for that particular message (see the definition of SnmpEngineID in the SNMP Architecture document RFC 3411).

The user's (private) authentication key is normally different at each authoritative SNMP engine and so the snmpEngineID is used to select the proper key for the authentication process.

7.2.3. SNMP Messages Using this Authentication Protocol

Messages using this authentication protocol carry a msgAuthenticationParameters field as part of the msgSecurityParameters.

For this protocol, the msgAuthenticationParameters field is the serialized OCTET STRING representing the first 12 octets of HMAC-SHA-96 output done over the wholeMsg.

The digest is calculated over the wholeMsg so if a message is authenticated, that also means that all the fields in the message are intact and have not been tampered with.

7.2.4. Services Provided by the HMAC-SHA-96 Authentication Module

This section describes the inputs and outputs that the HMAC-SHA-96 Authentication module expects and produces when the User-based Security module calls the HMAC-SHA-96 Authentication module for services.

7.2.4.1. Services for Generating an Outgoing SNMP Message

HMAC-SHA-96 authentication protocol assumes that the selection of the authKey is done by the caller and that the caller passes the secret key to be used.

Upon completion the authentication module returns statusInformation and, if the message digest was correctly calculated, the wholeMsg with the digest inserted at the proper place.

The abstract service primitive is:

statusInformation =              -- success or failure
authenticateOutgoingMsg(
IN authKey -- secret key for authentication
IN wholeMsg -- unauthenticated complete message
OUT authenticatedWholeMsg -- complete authenticated message
)

Parameters:

  • statusInformation: An indication of whether the authentication process was successful. If not it is an indication of the problem.

  • authKey: The secret key to be used by the authentication algorithm. The length of this key MUST be 20 octets.

  • wholeMsg: The message to be authenticated.

  • authenticatedWholeMsg: The authenticated message on output.

7.2.4.2. Services for Processing an Incoming SNMP Message

HMAC-SHA-96 authentication protocol assumes that the selection of the authKey is done by the caller and that the caller passes the secret key to be used.

Upon completion the authentication module returns statusInformation to indicate whether the message was authentic or not.

The abstract service primitive is:

statusInformation =              -- success or failure
authenticateIncomingMsg(
IN authKey -- secret key for authentication
IN authParameters -- as received on the wire
IN wholeMsg -- as received on the wire
OUT authenticatedWholeMsg -- checked for authentication
)

Parameters:

  • statusInformation: An indication of whether the authentication process was successful. If not it is an indication of the problem.

  • authKey: The secret key to be used by the authentication algorithm. The length of this key MUST be 20 octets.

  • authParameters: The msgAuthenticationParameters from the incoming message.

  • wholeMsg: The message to be authenticated.

  • authenticatedWholeMsg: The authenticated message on output.

7.3. Elements of Procedure

This section describes the procedures for the HMAC-SHA-96 authentication protocol.

7.3.1. Processing an Outgoing Message

This section describes the procedure followed by an SNMP engine when it generates a message containing management information on behalf of a user with an securityLevel that specifies authentication is to be used.

Step 1: Set msgAuthenticationParameters

The msgAuthenticationParameters field is set to the serialization according to the rules in RFC 3417 of an OCTET STRING containing 12 zero octets.

Step 2: Calculate the MAC

Using the secret authKey of the user, and the message with msgAuthenticationParameters set to 12 zero octets, calculate the MAC (Message Authentication Code) according to the HMAC-SHA algorithm:

MAC = HMAC-SHA(authKey, wholeMsg)

Where:

  • authKey is the 20-octet secret key
  • wholeMsg is the entire message with msgAuthenticationParameters set to 12 zero octets

Step 3: Truncate and Insert MAC

Take the first 12 octets of the 20-octet MAC value and place them in the msgAuthenticationParameters field.

Step 4: Return Result

Return the authenticatedWholeMsg to the calling module.

7.3.2. Processing an Incoming Message

This section describes the procedure followed by an SNMP engine when it processes a message containing management information with an securityLevel that specifies authentication has been used.

Step 1: Extract Parameters

Extract the msgAuthenticationParameters from the incoming message and save it.

Step 2: Set msgAuthenticationParameters to Zero

Replace the msgAuthenticationParameters field in the message with an OCTET STRING of 12 zero octets.

Step 3: Calculate Expected MAC

Using the secret authKey of the user, and the message with msgAuthenticationParameters set to 12 zero octets, calculate the expected MAC:

expectedMAC = HMAC-SHA(authKey, wholeMsg)

Step 4: Truncate Expected MAC

Take the first 12 octets of the 20-octet expectedMAC value.

Step 5: Compare MACs

Compare the extracted msgAuthenticationParameters (from step 1) with the calculated 12-octet MAC (from step 4).

If they are equal, the message is authenticated. If they are not equal, the message is not authentic and should be discarded.

Step 6: Return Result

Return statusInformation indicating success or failure.

Implementation Notes

  1. Key Length: The authKey MUST be exactly 20 octets for HMAC-SHA-96

  2. MAC Truncation: Only the first 96 bits (12 octets) of the 160-bit SHA output are used

  3. Constant-Time Comparison: When comparing MACs, implementations should use constant-time comparison to avoid timing attacks

  4. HMAC Mode: The protocol uses HMAC mode as specified in RFC 2104, not plain SHA

Security Considerations

  • SHA Strength: SHA-1 provides stronger cryptographic security than MD5. HMAC-SHA-96 is recommended over HMAC-MD5-96 for better security

  • Key Management: The 20-octet authKey must be kept secret and properly managed

  • Truncation: Truncating the MAC from 160 bits to 96 bits slightly reduces security but is considered acceptable for SNMP applications

  • Algorithm Selection: For new deployments, consider using SHA-2 or SHA-3 based HMAC variants if available