---
name: "kerberos"
section: "3"
platform: "linux"
package: "kerberos4kth-dev"
version: "1.2.2-11.2"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/kerberos/3"
---

# kerberos(3)

Kerberos authentication library

## NAME

krb\_mk\_req, krb\_rd\_req, krb\_kntoln, krb\_set\_key, krb\_get\_cred, krb\_mk\_priv, krb\_rd\_priv, krb\_mk\_safe, krb\_rd\_safe, krb\_mk\_err, krb\_rd\_err, krb\_ck\_repl - Kerberos authentication library

## SYNOPSIS

```
#include <des.h>
#include <krb.h>
```

**extern char \*krb\_err\_txt\[\];**

**int krb\_mk\_req(authent,service,instance,realm,checksum)** **KTEXT authent;** **char \*service;** **char \*instance;** **char \*realm;** **u\_long checksum;**

**int krb\_rd\_req(authent,service,instance,from\_addr,ad,fn)** **KTEXT authent;** **char \*service;** **char \*instance;** **u\_long from\_addr;** **AUTH\_DAT \*ad;** **char \*fn;**

**int krb\_kntoln(ad,lname)** **AUTH\_DAT \*ad;** **char \*lname;**

**int krb\_set\_key(key,cvt)** **char \*key;** **int cvt;**

**int krb\_get\_cred(service,instance,realm,c)** **char \*service;** **char \*instance;** **char \*realm;** **CREDENTIALS \*c;**

**long krb\_mk\_priv(in,out,in\_length,schedule,key,sender,receiver)** **u\_char \*in;** **u\_char \*out;** **u\_long in\_length;** **des\_cblock key;** **des\_key\_schedule schedule;** **struct sockaddr\_in \*sender;** **struct sockaddr\_in \*receiver;**

**long krb\_rd\_priv(in,in\_length,schedule,key,sender,receiver,msg\_data)** **u\_char \*in;** **u\_long in\_length;** **Key\_schedule schedule;** **des\_cblock key;** **struct sockaddr\_in \*sender;** **struct sockaddr\_in \*receiver;** **MSG\_DAT \*msg\_data;**

**long krb\_mk\_safe(in,out,in\_length,key,sender,receiver)** **u\_char \*in;** **u\_char \*out;** **u\_long in\_length;** **des\_cblock key;** **struct sockaddr\_in \*sender;** **struct sockaddr\_in \*receiver;**

**long krb\_rd\_safe(in,length,key,sender,receiver,msg\_data)** **u\_char \*in;** **u\_long length;** **des\_cblock key;** **struct sockaddr\_in \*sender;** **struct sockaddr\_in \*receiver;** **MSG\_DAT \*msg\_data;**

**long krb\_mk\_err(out,code,string)** **u\_char \*out;** **long code;** **char \*string;**

**long krb\_rd\_err(in,length,code,msg\_data)** **u\_char \*in;** **u\_long length;** **long code;** **MSG\_DAT \*msg\_data;**

## DESCRIPTION

This library supports network authentication and various related operations.  The library contains many routines beyond those described in this man page, but they are not intended to be used directly. Instead, they are called by the routines that are described, the authentication server and the login program.

*krb\_err\_txt\[\]* contains text string descriptions of various Kerberos error codes returned by some of the routines below.

*krb\_mk\_req* takes a pointer to a text structure in which an authenticator is to be built.  It also takes the name, instance, and realm of the service to be used and an optional checksum.  It is up to the application to decide how to generate the checksum. *krb\_mk\_req* then retrieves a ticket for the desired service and creates an authenticator.  The authenticator is built in *authent* and is accessible to the calling procedure.

It is up to the application to get the authenticator to the service where it will be read by *krb\_rd\_req.* Unless an attacker posesses the session key contained in the ticket, it will be unable to modify the authenticator.  Thus, the checksum can be used to verify the authenticity of the other data that will pass through a connection.

*krb\_rd\_req* takes an authenticator of type **KTEXT,** a service name, an instance, the address of the host originating the request, and a pointer to a structure of type **AUTH\_DAT** which is filled in with information obtained from the authenticator. It also optionally takes the name of the file in which it will find the secret key(s) for the service. If the supplied *instance* contains "\*", then the first service key with the same service name found in the service key file will be used, and the *instance* argument will be filled in with the chosen instance.  This means that the caller must provide space for such an instance name.

It is used to find out information about the principal when a request has been made to a service.  It is up to the application protocol to get the authenticator from the client to the service.  The authenticator is then passed to *krb\_rd\_req* to extract the desired information.

*krb\_rd\_req* returns zero (RD\_AP\_OK) upon successful authentication.  If a packet was forged, modified, or replayed, authentication will fail.  If the authentication fails, a non-zero value is returned indicating the particular problem encountered.  See *krb.h* for the list of error codes.

If the last argument is the null string (""), krb\_rd\_req will use the file /etc/srvtab to find its keys.  If the last argument is NULL, it will assume that the key has been set by *krb\_set\_key* and will not bother looking further.

*krb\_kntoln* converts a Kerberos name to a local name.  It takes a structure of type AUTH\_DAT and uses the name and instance to look in the database /etc/aname to find the corresponding local name.  The local name is returned and can be used by an application to change uids, directories, or other parameters.  It is not an integral part of Kerberos, but is instead provided to support the use of Kerberos in existing utilities.

*krb\_set\_key* takes as an argument a des key.  It then creates a key schedule from it and saves the original key to be used as an initialization vector. It is used to set the server's key which must be used to decrypt tickets.

If called with a non-zero second argument, *krb\_set\_key* will first convert the input from a string of arbitrary length to a DES key by encrypting it with a one-way function.

In most cases it should not be necessary to call *krb\_set\_key.* The necessary keys will usually be obtained and set inside *krb\_rd\_req. krb\_set\_key* is provided for those applications that do not wish to place the application keys on disk.

*krb\_get\_cred* searches the caller's ticket file for a ticket for the given service, instance, and realm; and, if a ticket is found, fills in the given CREDENTIALS structure with the ticket information.

If the ticket was found, *krb\_get\_cred* returns GC\_OK. If the ticket file can't be found, can't be read, doesn't belong to the user (other than root), isn't a regular file, or is in the wrong mode, the error GC\_TKFIL is returned.

*krb\_mk\_priv* creates an encrypted, authenticated message from any arbitrary application data, pointed to by *in* and *in\_length* bytes long. The private session key, pointed to by *key* and the key schedule, *schedule,* are used to encrypt the data and some header information using *pcbc\_encrypt.* *sender* and *receiver* point to the Internet address of the two parties. In addition to providing privacy, this protocol message protects against modifications, insertions or replays.  The encapsulated message and header are placed in the area pointed to by *out* and the routine returns the length of the output, or -1 indicating an error.

*krb\_rd\_priv* decrypts and authenticates a received *krb\_mk\_priv* message. *in* points to the beginning of the received message, whose length is specified in *in\_length.* The private session key, pointed to by *key,* and the key schedule, *schedule,* are used to decrypt and verify the received message. *msg\_data* is a pointer to a *MSG\_DAT* struct, defined in *krb.h.* The routine fills in the *app\_data* field with a pointer to the decrypted application data, *app\_length* with the length of the *app\_data* field, *time\_sec* and *time\_5ms* with the timestamps in the message, and *swap* with a 1 if the byte order of the receiver is different than that of the sender.  (The application must still determine if it is appropriate to byte-swap application data; the Kerberos protocol fields are already taken care of).  The *hash* field returns a value useful as input to the *krb\_ck\_repl* routine.

The routine returns zero if ok, or a Kerberos error code. Modified messages and old messages cause errors, but it is up to the caller to check the time sequence of messages, and to check against recently replayed messages using *krb\_ck\_repl* if so desired.

*krb\_mk\_safe* creates an authenticated, but unencrypted message from any arbitrary application data, pointed to by *in* and *in\_length* bytes long. The private session key, pointed to by *key,* is used to seed the *quad\_cksum()* checksum algorithm used as part of the authentication. *sender* and *receiver* point to the Internet address of the two parties. This message does not provide privacy, but does protect (via detection) against modifications, insertions or replays.  The encapsulated message and header are placed in the area pointed to by *out* and the routine returns the length of the output, or -1 indicating an error. The authentication provided by this routine is not as strong as that provided by *krb\_mk\_priv* or by computing the checksum using *cbc\_cksum* instead, both of which authenticate via DES.

*krb\_rd\_safe* authenticates a received *krb\_mk\_safe* message. *in* points to the beginning of the received message, whose length is specified in *in\_length.* The private session key, pointed to by *key,* is used to seed the quad\_cksum() routine as part of the authentication. *msg\_data* is a pointer to a *MSG\_DAT* struct, defined in *krb.h .* The routine fills in these *MSG\_DAT* fields: the *app\_data* field with a pointer to the application data, *app\_length* with the length of the *app\_data* field, *time\_sec* and *time\_5ms* with the timestamps in the message, and *swap* with a 1 if the byte order of the receiver is different than that of the sender. (The application must still determine if it is appropriate to byte-swap application data; the Kerberos protocol fields are already taken care of).  The *hash* field returns a value useful as input to the *krb\_ck\_repl* routine.

The routine returns zero if ok, or a Kerberos error code. Modified messages and old messages cause errors, but it is up to the caller to check the time sequence of messages, and to check against recently replayed messages using *krb\_ck\_repl* if so desired.

*krb\_mk\_err* constructs an application level error message that may be used along with *krb\_mk\_priv* or *krb\_mk\_safe.* *out* is a pointer to the output buffer, *code* is an application specific error code, and *string* is an application specific error string.

*krb\_rd\_err* unpacks a received *krb\_mk\_err* message. *in* points to the beginning of the received message, whose length is specified in *in\_length.* *code* is a pointer to a value to be filled in with the error value provided by the application. *msg\_data* is a pointer to a *MSG\_DAT* struct, defined in *krb.h .* The routine fills in these *MSG\_DAT* fields: the *app\_data* field with a pointer to the application error text, *app\_length* with the length of the *app\_data* field, and *swap* with a 1 if the byte order of the receiver is different than that of the sender.  (The application must still determine if it is appropriate to byte-swap application data; the Kerberos protocol fields are already taken care of).

The routine returns zero if the error message has been successfully received, or a Kerberos error code.

The *KTEXT* structure is used to pass around text of varying lengths.  It consists of a buffer for the data, and a length.  krb\_rd\_req takes an argument of this type containing the authenticator, and krb\_mk\_req returns the authenticator in a structure of this type.  KTEXT itself is really a pointer to the structure.   The actual structure is of type KTEXT\_ST.

The *AUTH\_DAT* structure is filled in by krb\_rd\_req.  It must be allocated before calling krb\_rd\_req, and a pointer to it is passed.  The structure is filled in with data obtained from Kerberos. *MSG\_DAT* structure is filled in by either krb\_rd\_priv, krb\_rd\_safe, or krb\_rd\_err.  It must be allocated before the call and a pointer to it is passed.  The structure is filled in with data obtained from Kerberos.

## FILES

/usr/include/krb.h\
 /usr/lib/libkrb.a\
 /usr/include/des.h\
 /usr/lib/libdes.a\
 /etc/aname\
 /etc/srvtab\
 /tmp/tkt\[uid\]

## SEE ALSO

[kerberos(1)](/kerberos/1.md), [des\_crypt(3)](/des_crypt/3.md)

## DIAGNOSTICS

## BUGS

The caller of *krb\_rd\_req, krb\_rd\_priv, and krb\_rd\_safe* must check time order and for replay attempts. *krb\_ck\_repl* is not implemented yet.

## AUTHORS

Clifford Neuman, MIT Project Athena\
 Steve Miller, MIT Project Athena/Digital Equipment Corporation

## RESTRICTIONS

COPYRIGHT 1985,1986,1989 Massachusetts Institute of Technology
