hash_algos

hash_algos(): array

Returns the list of registered hashing algorithms in the current environment.

C C23

C23
#include <stdio.h>
#include "sha256.h"

int main(void) {
    // C has no algorithm registry: which algorithms are supported depends on which implementations are linked (vendored sha256)
    SHA256_CTX ctx;
    BYTE digest[SHA256_BLOCK_SIZE];
    sha256_init(&ctx);
    sha256_update(&ctx, (const BYTE *)"x", 1);
    sha256_final(&ctx, digest);
    printf("sha256(\"x\") prefix byte: %02x\n", digest[0]);
    printf("digest size: %d\n", SHA256_BLOCK_SIZE);
    return 0;
}
Output
sha256("x") prefix byte: 2d
digest size: 32

C++ C++26

C++26
#include <cstdio>
#include <iostream>
#include "sha256.h"

int main() {
    // C++ same as C: the linked implementation decides the algorithms (OpenSSL, libsodium, etc.)
    SHA256_CTX ctx;
    BYTE digest[SHA256_BLOCK_SIZE];
    sha256_init(&ctx);
    sha256_update(&ctx, (const BYTE *)"x", 1);
    sha256_final(&ctx, digest);
    char prefix[3];
    snprintf(prefix, sizeof prefix, "%02x", digest[0]);
    std::cout << "sha256(\"x\") prefix byte: " << prefix << "\n";
    std::cout << "digest size: " << SHA256_BLOCK_SIZE << "\n";
    return 0;
}
Output
sha256("x") prefix byte: 2d
digest size: 32

C# v11.0.100

v11.0.100
using System.Security.Cryptography;

// .NET has no central algorithm listing: the idiom is to construct instances directly — failure means unsupported
Console.WriteLine(SHA256.HashData(new byte[] { 0x78 }).Length == 32);
Console.WriteLine(MD5.HashData(new byte[] { 0x78 }).Length == 16);
Output
True
True

Go v1.27.4

v1.27.4
package main

import (
	"crypto"
	_ "crypto/md5" // Blank imports trigger the algorithm implementation registration
	_ "crypto/sha256"
	_ "crypto/sha512"
	"fmt"
)

func main() {
	// Go has no runtime listing: algorithms are crypto.Hash constants; Available() checks whether an implementation is registered
	fmt.Println(crypto.MD5.Available(), crypto.SHA256.Available(), crypto.SHA512.Available())
	fmt.Println(crypto.SHA256.New().Size())
}
Output
true true true
32

Java v27.0.1

v27.0.1
import java.security.Provider;
import java.security.Security;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        // No direct listing API: walk every Provider collecting MessageDigest service names
        TreeSet<String> algos = new TreeSet<>();
        for (Provider p : Security.getProviders()) {
            for (Provider.Service s : p.getServices()) {
                if (s.getType().equals("MessageDigest")) algos.add(s.getAlgorithm());
            }
        }
        System.out.println(algos.contains("SHA-256"));
        System.out.println(algos.contains("MD5"));
        System.out.println(algos.contains("MD2") ? "MD2 supported" : "MD2 missing");
    }
}
Output
true
true
MD2 supported

JavaScript v26.13.1

v26.13.1
// Node getHashes: the listing varies with the OpenSSL build; this only demos the support query
const crypto = require("node:crypto");
const hashes = crypto.getHashes();
console.log(hashes.includes("sha256"));
console.log(hashes.includes("md5"));
try {
  crypto.createHash("nope");
} catch {
  console.log("bad algo throws");
}
Output
true
true
bad algo throws

PHP v8.6.0

v8.6.0
// hash_algos: returns every registered algorithm (the listing grows with PHP versions — never hard-code it)
$algos = hash_algos();
print_r(array_slice($algos, 0, 8));
// Support query: check in_array in code rather than assume
var_dump(in_array("sha256", $algos), in_array("md5", $algos));
echo in_array("xxh128", $algos) ? "xxh128 supported\n" : "xxh128 missing\n";
Output
Array
(
    [0] => md2
    [1] => md4
    [2] => md5
    [3] => sha1
    [4] => sha224
    [5] => sha256
    [6] => sha384
    [7] => sha512/224
)
bool(true)
bool(true)
xxh128 supported

Python v3.15.2

v3.15.2
import hashlib

# algorithms_guaranteed is cross-platform guaranteed; algorithms_available is the full local set (including OpenSSL's dynamic registrations)
print(sorted(hashlib.algorithms_guaranteed)[:8])
# Support query: hashlib.new constructs by name; an unknown algorithm raises ValueError
print("sha256" in hashlib.algorithms_available)
try:
    hashlib.new("nope")
except ValueError:
    print("bad algo throws")
Output
['blake2b', 'blake2s', 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha3_224']
True
bad algo throws

Rust v1.99.1

v1.99.1
// Rust has no global algorithm registry: algorithms are concrete types (Sha256/Sha512 etc. come from third-party crates);
// std only ships the non-cryptographic DefaultHasher (SipHash-1-3, used by HashMap)
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

fn main() {
    // "algorithms as types": same type + same input always yields the same digest
    let mut h1 = DefaultHasher::new();
    let mut h2 = DefaultHasher::new();
    "x".hash(&mut h1);
    "x".hash(&mut h2);
    println!("{}", h1.finish() == h2.finish());
    println!("{}", std::mem::size_of::<u64>());
}
Output
true
8

TypeScript v26.13.1

v26.13.1
import { createHash, getHashes } from "node:crypto";

// Node getHashes: the listing varies with the OpenSSL build; this only demos the support query
const hashes: string[] = getHashes();
console.log(hashes.includes("sha256"));
console.log(hashes.includes("md5"));
try {
  createHash("nope");
} catch {
  console.log("bad algo throws");
}
Output
true
true
bad algo throws

Language differences

C: no registry — the supported set equals what you link in (the bundled vendor sha256 here); against a shared OpenSSL, enumerate with EVP_MD_do_all.

C++: same as C; OpenSSL's EVP_get_digestbyname fetches by name and EVP_MD_do_all lists them.

C#: no listing API — static factories like SHA256.Create() instantiate directly; unsupported algorithms are invisible at compile time (the type system is the registry).

Go: crypto.Hash constants plus Available() checks; implementation packages (crypto/sha256, ...) must be imported explicitly to register.

Java: walking Security.getProviders() collecting MessageDigest services is the only generic enumeration; algorithm names are case-insensitive (SHA-256 or sha256).

JavaScript: Node's crypto.getHashes() returns the digests available from the current OpenSSL build; createHash throws on unknown names.

PHP: hash_algos() lists all registered algorithms (hash_hmac_algos() restricts to HMAC-capable ones); names are lowercase and lookups are case-insensitive.

Python: hashlib.algorithms_guaranteed is the cross-platform guaranteed set; algorithms_available is the machine's full set (including OpenSSL extras); hashlib.new(name) constructs by name.

Rust: no runtime registry — choosing an algorithm is choosing a type (RustCrypto's Sha256/Sha512, ...); std's DefaultHasher is not cryptographic.

TypeScript: same as JavaScript — getHashes plus createHash.