/* SPDX-License-Identifier: GPL-2.0 */1/*2* Implementations of the security context functions.3*4* Author: Ondrej Mosnacek <[email protected]>5* Copyright (C) 2020 Red Hat, Inc.6*/78#include <linux/jhash.h>910#include "context.h"11#include "mls.h"1213u32 context_compute_hash(const struct context *c)14{15u32 hash = 0;1617/*18* If a context is invalid, it will always be represented by a19* context struct with only the len & str set (and vice versa)20* under a given policy. Since context structs from different21* policies should never meet, it is safe to hash valid and22* invalid contexts differently. The context_equal() function23* already operates under the same assumption.24*/25if (c->len)26return full_name_hash(NULL, c->str, c->len);2728hash = jhash_3words(c->user, c->role, c->type, hash);29hash = mls_range_hash(&c->range, hash);30return hash;31}323334