HSM KitHSM Kit
English

SafeNet Key Management: Luna HSM & KM Key Variants

Key Management# SafeNet# Luna# HSM# Key Management
Last Updated: May 21, 20264 min readBy HSM Kit Team
Need to calculate this now?
Use our free online SafeNet Keys Tool tool.

SafeNet HSMs, now part of Thales, are widely used for general-purpose cryptography, PKI, and key management. This guide covers SafeNet's key management approach, including KM Key variants, key lookup mechanisms, and practical usage scenarios.

SafeNet Luna HSM Overview

SafeNet Luna is a family of HSMs used across various industries for:

  • PKI certificate authorities
  • SSL/TLS key protection
  • Database encryption
  • Code signing
  • Document signing
  • General cryptographic operations

Unlike payment-focused HSMs (Thales payShield, Futurex), SafeNet Luna HSMs are general-purpose devices optimized for performance and flexibility.

Luna vs Payment HSMs

FeatureSafeNet LunaPayment HSM
Primary usePKI, encryptionPIN, payment processing
Key formatKM Key variantsThales LMK, Futurex scheme
StandardsPKCS#11, JCEANSI X9.24, PCI PIN
DeploymentEnterprise, cloudBanks, processors

KM Key Variant System

SafeNet uses a key management system based on KM Key variants to protect stored keys.

What is a KM Key?

The KM Key (Key Management Key) is the root key in SafeNet's hierarchy. It's analogous to the MFK in Futurex or the LMK in Thales systems.

Key characteristics:

  • Generated inside the HSM during initialization
  • Split into components for security
  • Never exported in plaintext
  • Used to encrypt all other keys

Variant Encryption

SafeNet applies variant encryption by XORing different masks with the KM Key before encrypting other keys:

Encrypted Key = E(KM_Key XOR variant_mask, plaintext_key)

This ensures different key types are cryptographically separated.

Common Variant Masks

Key TypeVariant Purpose
Storage KeyEncrypts keys for persistent storage
Session KeyProtects temporary keys
Export KeyWraps keys for export
Domain KeySeparates keys by security domain

Key Lookup Flow

SafeNet HSMs use a key lookup mechanism to find and use stored keys efficiently.

How Key Lookup Works

  1. Application requests key by alias or handle
  2. HSM searches key store for matching entry
  3. Key is retrieved from secure storage
  4. Key is decrypted under KM Key variant
  5. Key is loaded into cryptographic processor
  6. Operation is performed
  7. Key is cleared from working memory

Key Handles vs Aliases

IdentifierTypeDescription
HandleNumericAuto-generated reference
AliasStringHuman-readable name

Handles are faster for frequent operations; aliases are better for management.

Luna Key Management Architecture

Partition-Based Security

SafeNet Luna uses partitions to isolate keys and operations:

  • Each partition has its own KM Key
  • Keys in one partition cannot access another
  • Partitions can be assigned to different applications
  • Enables multi-tenant deployments

Key Backup and Restore

Keys can be backed up securely:

  1. Export keys under backup key encryption
  2. Store encrypted backup externally
  3. Restore by importing under same backup key
  4. Verify KCVs after restore

Practical Scenarios

PKI Certificate Authority

Using SafeNet Luna for a CA:

  1. Generate CA private key inside HSM
  2. Key never leaves HSM in plaintext
  3. Sign certificates using HSM
  4. Store intermediate CA keys in separate partitions
  5. Enforce key usage policies

Database Encryption

Protecting database encryption keys:

  1. Generate Data Encryption Key (DEK) in HSM
  2. Encrypt DEK under KM Key variant
  3. Application retrieves DEK via API
  4. Database uses DEK for field encryption
  5. DEK cached in memory only during operation

Cloud Key Management

SafeNet Luna for cloud deployments:

  1. Deploy Luna Cloud HSM
  2. Generate keys in cloud HSM
  3. Keys protected by cloud KM Key
  4. Application accesses via REST API
  5. Full audit trail maintained

Key Export and Import

Exporting Keys

When exporting a key from SafeNet Luna:

  1. Key is decrypted from KM Key variant
  2. Key is encrypted under target key (partner's wrapping key)
  3. Encrypted key is returned
  4. KCV is included for verification

Importing Keys

When importing a key:

  1. Key arrives encrypted under wrapping key
  2. HSM decrypts using wrapping key
  3. Key is encrypted under KM Key variant
  4. Key is stored in partition
  5. KCV is verified

Common Issues

Partition Isolation

If you can't find a key:

  • Verify you're querying the correct partition
  • Check partition authentication
  • Ensure key was stored in expected partition

Key Handle Invalidation

Key handles may become invalid after:

  • HSM restart (if not persistent)
  • Partition re-initialization
  • Key deletion

Use aliases for persistent references.

Performance Considerations

Key lookup performance depends on:

  • Number of keys in partition
  • Key alias vs handle usage
  • HSM load and concurrency

Best Practices

  1. Use partitions to isolate different applications
  2. Name keys consistently with clear alias conventions
  3. Regular backups using Luna backup mechanisms
  4. Monitor key usage through HSM audit logs
  5. Rotate keys according to policy

Try It Yourself

Use our SafeNet Keys tool to:

  • Understand KM Key variant structure
  • Parse SafeNet key formats
  • Calculate KCVs for verification
  • Explore key management concepts

The tool runs entirely in your browser — no data leaves your device.

Related Tool
SafeNet Keys Tool