OpenNHP/opennhp · error

signature verification failed

Error message

signature verification failed

What it means

After decrypting, DecryptZtdoFile reads the trailing signature block and calls signature.verify(recalcSig), which recomputes the expected signature (recalcSig) and compares it with the one stored in the file. A mismatch means the file content was altered after signing or the signature was produced with different keys/data. The library throws to refuse processing tampered or mis-signed data.

Solutions

  1. Confirm the file came from a trusted, unmodified source and re-download/re-copy it.
  2. Check that the signing key used by the producer matches the verification key expected here.
  3. Regenerate the file: re-create the ztdo (including metadata/signature) from the original data instead of patching the corrupted one.
  4. If you produce signed files, verify the signature immediately after writing to catch serialization-order bugs.

Example fix

// before: assume file intact
err := ztdo.DecryptZtdoFile(f, pass)
// after: detect and surface tampering distinctly
if err := ztdo.DecryptZtdoFile(f, pass); err != nil {
    if strings.Contains(err.Error(), "signature verification failed") {
        return ErrTamperedZtdo // treat as security event, not I/O error
    }
    return err
}
Defensive patterns

Strategy: try-catch

Try / catch

if err := ztdo.DecryptZtdoFile(f, pass); err != nil {
    if strings.Contains(err.Error(), "signature verification failed") {
        log.SecurityEvent("ztdo_signature_mismatch", path)
        return ErrTampered
    }
    return err
}

Prevention

When it happens

Trigger: Calling DecryptZtdoFile on a signed ztdo file where signature.verify() returns false — the stored signature does not match the recalculated signature over the decrypted content.

Common situations: File modified after signing (edited metadata, re-chunked content); signed by a different key than the one used to verify; a bug in a custom writer that serialized the header/signature out of order; partial re-encryption of the file by another tool.

Understand the failure class

Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.

Related errors


AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07). Data as JSON: /api/errors/906bae33dfea8d20. Report an issue: GitHub.

Appendix: source

Thrown at nhp/core/ztdo/ztdo.go:476

				return fmt.Errorf("invalid ztdo file")
			}
		} else {
			if remainingCiphertextFileSize == 0 {
				break
			}
		}
	}

	// update recalculated signature
	recalcSig.sign(gcmKey)

	if ztdo.header.HasSignature() {
		if err := toStructure(ciphertextFile, &ztdo.signature); err != nil {
			return err
		}

		if !ztdo.signature.verify(recalcSig) {
			return fmt.Errorf("signature verification failed")
		}
	}

	return nil
}

// marshal searilizs Go struct into bytes buffer
func marshal(buf *bytes.Buffer, data any) error {
	rData := reflect.ValueOf(data)
	if rData.Kind() == reflect.Pointer {
		rData = rData.Elem()
	}

	if rData.Kind() != reflect.Struct {
		return fmt.Errorf("data must be a struct")
	}

	for i := range rData.NumField() {

View on GitHub (pinned to 6e04ca5ff0)