+static bool_t check_msg(struct site *st, uint32_t type, struct msg *m,
+ cstring_t *error)
+{
+ if (type==LABEL_MSG1) return True;
+
+ /* Check that the site names and our nonce have been sent
+ back correctly, and then store our peer's nonce. */
+ if (memcmp(m->remote,st->remotename,strlen(st->remotename)!=0)) {
+ *error="wrong remote site name";
+ return False;
+ }
+ if (memcmp(m->local,st->localname,strlen(st->localname)!=0)) {
+ *error="wrong local site name";
+ return False;
+ }
+ if (memcmp(m->nL,st->localN,NONCELEN)!=0) {
+ *error="wrong locally-generated nonce";
+ return False;
+ }
+ if (type==LABEL_MSG2) return True;
+ if (memcmp(m->nR,st->remoteN,NONCELEN)!=0) {
+ *error="wrong remotely-generated nonce";
+ return False;
+ }
+ if (type==LABEL_MSG3) return True;
+ if (type==LABEL_MSG4) return True;
+ *error="unknown message type";
+ return False;
+}
+